I am trying, since a few weeks, to develop a B4A application to consult the real time price of stocks.  The best results have been obtained using the TestjSoup project published by Erel.  I modified the code under the btnLoadFromURL button to connect the Yahoo page first and Zacks page finally, and the process runs very well. I added an edittextbox (tx_tkt) to enter the ticket code of the stock to be consulted and three labels to show the three values generally desired: price, day change and % of change.
When I click the btnLoadFromURL button, the program sends the url and the ticket stock code storaged in the tx_tkt Edittextbox as a parameter and the page responds sending all the text contained in it. With a Function (ExtractValues), created by me some years ago in vb.net, converted to B4A , I scrape the text and fill the three response labels.
I have had two main problems: the Yahoo page detects that I am not a regular user and sends a correct response but with old data and the second one: when I create an executable version, using release insted of debug, I receive the error: android.os.NetworkOnMainThreadException, and the page did not connect. For the first problem I decided to run away, because I supposed that I have nothing to do, to solve it. Better, I went to Zacks page. For the second one, I would like to hear solutions and sugestions from you.
The code used to call the page is
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
			
			When I click the btnLoadFromURL button, the program sends the url and the ticket stock code storaged in the tx_tkt Edittextbox as a parameter and the page responds sending all the text contained in it. With a Function (ExtractValues), created by me some years ago in vb.net, converted to B4A , I scrape the text and fill the three response labels.
I have had two main problems: the Yahoo page detects that I am not a regular user and sends a correct response but with old data and the second one: when I create an executable version, using release insted of debug, I receive the error: android.os.NetworkOnMainThreadException, and the page did not connect. For the first problem I decided to run away, because I supposed that I have nothing to do, to solve it. Better, I went to Zacks page. For the second one, I would like to hear solutions and sugestions from you.
The code used to call the page is
			
				B4X:
			
		
		
		Private Sub btnLoadFromURL_Click
    Dim x As String
    Dim n As Int
    url = "https://www.zacks.com/stock/quote/" & tx_tkt.Text.ToUpperCase
    n=0
   
    Try
        x=js.connect(url)
        n=x.Length
    Catch
        tx_texto.Text=LastException
        x=""
    End Try
       
    n=x.IndexOf("<header>")                        'beguining of the price block of text                          
    If n>0 Then
        x=x.SubString(n)
        n=x.IndexOf("change")                    'end of the price block of text
        If n>0 Then
            x=x.SubString2(0,n+200)
            tx_texto.Text=x
            ExtractValues(tx_texto.text)
        End If
    End If
End Sub
			
				Last edited: 
			
		
	
								
								
									
	
								
							
							 
				 
 
		 
 
		 
 
		 
 
		 
						
					 
 
		 
 
		 
 
		