How to get values from a web page
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
mandai wrote:Hello, I'm sorry but I haven't figured out where to add ComboBox1.Items.Clear (), I tried here:KraZy wrote: the combobox, it seems that teams are added several times. How can fix this?You can use ComboBox1.Items.Clear to reset the team list, this can be added in the WebBrowser1_DocumentCompleted event.
KraZy wrote: let me ask if you can get the same result with the Http Request?It is possible to use HttpWebRequest instead of the WebBrowser, but you would need to add code in order to parse the HTML.
Code: Select all
but the code continues to give the same problems. If Teams.Count> 20 Then
WebBrowser1.Stop ()
ComboBox1.Items.Clear ()
end If
However, I tried to read the contents of the html page, and so I did:
Code: Select all
the problem is that I can not use document.getElementsByTagName because it is a string, and I need your help to make it happen.Dim pagehtml As String = New System.Net.WebClient().DownloadString("http://it.soccerway.com/national/italy/serie-a/20142015/regular-season/r27139/")
I'm in the empire business.
KraZy wrote:Great, you're the best, you are able to figure out what I wanted and the code is really very simple and powerful so I could understand it. clapper;In this code I made it so the combobox doesn't add multiple instances of a team. However, I did not use a HttpRequest. I am still using a webbrowser because when I did use a Httprequest it ended up being really complicated because I don't understand it really well. Also you can select either series a or b and it will find the teams in there as well
There's only one small problem, the combobox, it seems that teams are added several times. How can fix this?
I then saw that the championships are uploaded to the site a list, it would be possible to get the data list such as "Series A" and load only the teams from that league?
Image example:
Update:
I read on the net that with the HttpRequest would be much faster than the software, in fact I have noticed a marked slowdown of the application due to the WebBrowser control. Before proceeding, let me ask if you can get the same result with the Http Request?
Why I would make sure to get the values form present in the field div, and until now I'm trying in vain. So you could opt for the Http Request, if it is not a problem for her. Thank you for your patience. Have a good Sunday.
Code: Select all
Public Class Form1
Dim Teams, PG, V, N, P, R, P2 As New List(Of String)
Dim urls As String() = {"http://it.soccerway.com/national/italy/serie-a/20142015/regular-season/r27139/", "http://it.soccerway.com/national/italy/serie-b/c14/"}
Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If Not WebBrowser1.IsBusy Then
Try
Teams.Clear()
PG.Clear()
V.Clear()
N.Clear()
P.Clear()
R.Clear()
P2.Clear()
ComboBox1.Items.Clear()
ComboBox2.Items.Clear()
Dim elementTable As HtmlElement = WebBrowser1.Document.GetElementsByTagName("tbody")(2)
Dim elementRows As HtmlElementCollection = elementTable.GetElementsByTagName("tr")
For i As Integer = 0 To elementRows.Count - 1
Dim elementColumns As HtmlElementCollection = elementRows(i).GetElementsByTagName("td")
Teams.Add(elementColumns(2).InnerText)
PG.Add(elementColumns(3).InnerText)
V.Add(elementColumns(4).InnerText)
N.Add(elementColumns(5).InnerText)
P.Add(elementColumns(6).InnerText)
R.Add(elementColumns(7).InnerText)
P2.Add(elementColumns(8).InnerText)
Next
ComboBox1.Items.AddRange(Teams.ToArray())
ComboBox2.Items.AddRange(Teams.ToArray())
Catch ex As Exception
End Try
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
NumericUpDown1.Value = PG(ComboBox1.SelectedIndex)
NumericUpDown2.Value = V(ComboBox1.SelectedIndex)
'etc'
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
NumericUpDown1.Value = PG(ComboBox2.SelectedIndex)
NumericUpDown2.Value = V(ComboBox2.SelectedIndex)
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
WebBrowser1.ScriptErrorsSuppressed = True
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
WebBrowser1.Navigate(urls(ComboBox3.SelectedIndex))
End Sub
End Class
Thank you for the help you are giving me, I'm really grateful.
For now, I'm not going to go to Http Request, maybe in the future I will study this obscure field of vb.net, but today I learned a lot with your code example. cooll;
I noticed that if I select a team in comboBox1 and then I select a team in ComboBox2, the team selected in the comboBox1 disappears, but the values loaded into the NumericUpDown remain loaded in objects. This is just a flaw chart...
About the latest revision of the code, which you kindly provided I would like to ask you some questions. I do not want to abuse of your time since you have been very kind, and all the others who are supporting me in this topic.
I need to capture the values form, but unfortunately these are available in a div and not in an html table, is from this morning that I'm trying to peck away the object code but I can't. I'm attaching a picture for you to understand better and the other values with the new assembly, hoping he wouldn't ask too much from you, thank you for giving your valuable time spent.
Image Example:

For now, I'm not going to go to Http Request, maybe in the future I will study this obscure field of vb.net, but today I learned a lot with your code example. cooll;
I noticed that if I select a team in comboBox1 and then I select a team in ComboBox2, the team selected in the comboBox1 disappears, but the values loaded into the NumericUpDown remain loaded in objects. This is just a flaw chart...
About the latest revision of the code, which you kindly provided I would like to ask you some questions. I do not want to abuse of your time since you have been very kind, and all the others who are supporting me in this topic.

I need to capture the values form, but unfortunately these are available in a div and not in an html table, is from this morning that I'm trying to peck away the object code but I can't. I'm attaching a picture for you to understand better and the other values with the new assembly, hoping he wouldn't ask too much from you, thank you for giving your valuable time spent.
Image Example:

You do not have the required permissions to view the files attached to this post.
I'm in the empire business.
Copyright Information
Copyright © Codenstuff.com 2020 - 2023