I am trying to get all participant name value from the list with (span class=text) and also their shortname value with (class=contenu) and add them to the different coloumn of the listview item which will shown as similiart to the web page. The user can see the full name of the participant and also can click the individual participant brand (short name) to get more detail.
Imports HtmlAgilityPack
Public Class Form1
Dim web As New HtmlWeb
Dim doc As HtmlDocument = web.Load("http://www.eurovent-certification.com/en/Certified_products/Access_by_programme.php?rub=04&srub=01&ssrub=&lg=en&select_prog=AHU")
Dim ParticipantNodesShort As HtmlNodeCollection = doc.DocumentNode.SelectNodes("/html/body/table/tr/td[2]/table[4]/tr[2]/td[2]//a[@class='contenu']")
Dim ParticipantNodesLong As HtmlNodeCollection = doc.DocumentNode.SelectNodes("/html/body/table/tr/td[2]/table[4]/tr[2]/td[2]//span[@class='texte']")
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
' Adding ListView Columns
ListView2.Columns.Add("Participant's contact - Full Name", 250, HorizontalAlignment.Left)
ListView2.Columns.Add("Brand Name", 100, HorizontalAlignment.Left)
ListView2.Columns.Add("Brand Name", 100, HorizontalAlignment.Left)
ListView2.Columns.Add("Brand Name", 100, HorizontalAlignment.Left)
ListView2.Columns.Add("Brand Name", 100, HorizontalAlignment.Left)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim web As New HtmlWeb
Dim doc As HtmlDocument = web.Load("http://www.eurovent-certification.com/en/Certified_products/Access_by_programme.php?rub=04&srub=01&ssrub=&lg=en&select_prog=AHU")
Dim ParticipantNodes As HtmlNodeCollection = doc.DocumentNode.SelectNodes("/html/body/table/tr/td[2]/table[4]/tr[2]/td[2]//span[@class='texte'] | /html/body/table/tr/td[2]/table[4]/tr[2]/td[2]//a[@class='contenu']")
Dim participantname(20) As String
Dim brandname(50) As String
Dim participantcount As Integer = 0
Dim brandcount As Integer = 0
For Each item As HtmlNode In ParticipantNodes
If item.Name = "span" Then
Debug.Print(participantname(participantcount))
participantname(participantcount) = item.InnerText.Replace(vbLf, "").Replace(vbCr, "").Replace(vbTab, "")
participantcount = participantcount + 1
Else
If Not item.Attributes.Count = 3 Then
brandname(brandcount) &= String.Format(" [{0}]", item.InnerText.Replace(vbLf, "").Replace(vbCr, "").Replace(vbTab, ""))
brandcount = brandcount + 1
End If
End If
ListView2.Items.Add(participantname(participantcount) & " " & brandname(brandcount))
Next
End Sub
End Class
Try to simplify the problem ;
This is the part from the full page which shows participant names and their brands ( some of them has one and some other has two, three or four)
like below ; Mekar srl (Participant Name) has 4 different brand which are separated with comma ( Eden, Mekar VENCO, Venticlima)
MEKAR s.r.l. ( EDEN , MEKAR , VENCO , VENTILCLIMA )
but some of them only one ;
like below example ; Menegra Gmbh ( participant name) has only one brand as Menegra MENERGA GmbH ( Menerga )
So i will try to write these data almost the same logic with the page to a listview ;
1st column will be listing participant name and with the same row at the second column brand name will be listed ( or if more then one, third and fourth column of the same row)
Regardless from the listview i need to get idea to hold the data that i get from the webpage to record at the array type string and show them at the listview later.
With the code above i am reading all the nodes continuosly and lost the relations between them ( like participant name with multiple brand)
Hope this statement will be more clear which i also hope again to get more support
Regards
Ali
Ok so I did some quick googling on ListView...here are the results.
This is part of the output:
I haven't used listview that much so I'm not familiar with it, and since you have a variable amount of columns i would store these results somewhere temporarily then check how many columns I need to make. Then just dump the results in listview.