How to get title inside table using HtmlAgility pack? - vb.net

Hello I am trying to get the "title" element out of this table:
<td class="field_domain"><strong>Plantar</strong><strong>Fasciitis</strong>HeelPain.com</td>
Here is my code that almost works but not quite:
Dim web As New HtmlAgilityPack.HtmlWeb()
Dim htmlDoc As HtmlAgilityPack.HtmlDocument = web.Load("https://www.expireddomains.net/domain-name-search/?o=domainpop&r=d&q=plantar+fasciitis")
Dim html As String = htmlDoc.DocumentNode.OuterHtml
Dim tabletag = htmlDoc.DocumentNode.SelectNodes("//td[#class='field_domain']")
For Each t In tabletag
Dim var = t.SelectSingleNode("//td[#class='title']").InnerText
MessageBox.Show(var)
Next

This did the trick:
Dim web As New HtmlAgilityPack.HtmlWeb()
Dim htmlDoc As HtmlAgilityPack.HtmlDocument = web.Load("https://www.expireddomains.net/domain-name-search/?o=domainpop&r=d&q=plantar+fasciitis")
Dim html As String = htmlDoc.DocumentNode.OuterHtml
For Each linkItem As HtmlNode In htmlDoc.DocumentNode.SelectNodes("//td[#class='field_domain']")
Dim name = linkItem.Element("a").InnerText
MessageBox.Show(name)
Next

Related

adding multiple text files to gridview (devexpress) in vb.net

I have a folder with multiple text files in it, each text files has about 14 lines of text.
I would like to add all text files in that folder to a gridcontrol/gridview in vb.net.
My current code only adds 1 text file instead of adding all. any help would be greatly appreciated.
Dim path As String = "C:\Plan\"
For Each i As String In System.IO.Directory.GetFiles(path)
Dim a, b, c As String
a = System.IO.Path.GetFileNameWithoutExtension(i)
b = System.IO.Path.GetFileName(i)
c = System.IO.Path.GetFullPath(i)
Dim LINE_pair As String = IO.File.ReadLines(i).ElementAtOrDefault(0)
Dim LINE1_details As String = IO.File.ReadLines(i).ElementAtOrDefault(1)
Dim LINE2_outlookcombo As String = IO.File.ReadLines(i).ElementAtOrDefault(2)
Dim LINE3_rsicombo As String = IO.File.ReadLines(i).ElementAtOrDefault(3)
Dim LINE4_macdcombo As String = IO.File.ReadLines(i).ElementAtOrDefault(4)
Dim LINE4_ratio As String = IO.File.ReadLines(i).ElementAtOrDefault(5)
Dim LINE5_pattern As String = IO.File.ReadLines(i).ElementAtOrDefault(6)
Dim LINE6_none As String = IO.File.ReadLines(i).ElementAtOrDefault(7)
Dim LINE7_timeframecomvo As String = IO.File.ReadLines(i).ElementAtOrDefault(8)
Dim LINE7_date As String = IO.File.ReadLines(i).ElementAtOrDefault(9)
Dim LINE8_trade As String = IO.File.ReadLines(i).ElementAtOrDefault(10)
Dim LINE9_currentprice As String = IO.File.ReadLines(i).ElementAtOrDefault(11)
Dim LINE10_tp As String = IO.File.ReadLines(i).ElementAtOrDefault(12)
Dim LINE11_sl As String = IO.File.ReadLines(i).ElementAtOrDefault(13)
Dim NewItem As New ListViewItem(a)
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(13) {New DataColumn("Pair"), New DataColumn("Outlook"), New DataColumn("RSI"), New DataColumn("MACD"), New DataColumn("Pattern"), New DataColumn("Misc"), New DataColumn("Rato"), New DataColumn("Time Frame"), New DataColumn("Date"), New DataColumn("File name"), New DataColumn("Trade Status"), New DataColumn("CP"), New DataColumn("TP"), New DataColumn("SL")})
dt.Rows.Add(New String() {LINE_pair, LINE2_outlookcombo, LINE3_rsicombo, LINE4_macdcombo, LINE5_pattern, LINE6_none, LINE4_ratio, LINE7_timeframecomvo, LINE7_date, a, LINE8_trade, LINE9_currentprice, LINE10_tp, LINE11_sl})
GridControl1.DataSource = dt
It is not necessary to declare the DataColumn array explicitly. It is created internally from the items in the braces.
You are throwing away your NewItem on each iteration. Why not add them to a list and add them all at once to a ListView.
You are reading the file over and over as you assign the LINE_ data. Read it once and use the resulting lines array.
You never use b and c in this code so I deleted them
I tested in with a .net DataGridView. The file io methods and the DataTable are the same.
Private Sub OPCode()
Dim path As String = "C:\Plan\"
Dim dt As New DataTable()
Dim lstListViewItems As New List(Of ListViewItem)
dt.Columns.AddRange({New DataColumn("Pair"), New DataColumn("Outlook"), New DataColumn("RSI"), New DataColumn("MACD"), New DataColumn("Pattern"), New DataColumn("Misc"), New DataColumn("Rato"), New DataColumn("Time Frame"), New DataColumn("Date"), New DataColumn("File name"), New DataColumn("Trade Status"), New DataColumn("CP"), New DataColumn("TP"), New DataColumn("SL")})
For Each i As String In System.IO.Directory.GetFiles(path)
Dim a = System.IO.Path.GetFileNameWithoutExtension(i)
Dim lines = File.ReadLines(i)
Dim LINE_pair As String = lines.ElementAtOrDefault(0)
Dim LINE1_details As String = lines.ElementAtOrDefault(1)
Dim LINE2_outlookcombo As String = lines.ElementAtOrDefault(2)
Dim LINE3_rsicombo As String = lines.ElementAtOrDefault(3)
Dim LINE4_macdcombo As String = lines.ElementAtOrDefault(4)
Dim LINE4_ratio As String = lines.ElementAtOrDefault(5)
Dim LINE5_pattern As String = lines.ElementAtOrDefault(6)
Dim LINE6_none As String = lines.ElementAtOrDefault(7)
Dim LINE7_timeframecomvo As String = lines.ElementAtOrDefault(8)
Dim LINE7_date As String = lines.ElementAtOrDefault(9)
Dim LINE8_trade As String = lines.ElementAtOrDefault(10)
Dim LINE9_currentprice As String = lines.ElementAtOrDefault(11)
Dim LINE10_tp As String = lines.ElementAtOrDefault(12)
Dim LINE11_sl As String = lines.ElementAtOrDefault(13)
dt.Rows.Add({LINE_pair, LINE2_outlookcombo, LINE3_rsicombo, LINE4_macdcombo, LINE5_pattern, LINE6_none, LINE4_ratio, LINE7_timeframecomvo, LINE7_date, a, LINE8_trade, LINE9_currentprice, LINE10_tp, LINE11_sl})
Dim NewItem As New ListViewItem(a)
lstListViewItems.Add(NewItem)
Next
ListView1.Items.AddRange(lstListViewItems.ToArray)
DataGridView1.DataSource = dt
End Sub

How to fix "Windows Security Warning" popup issue while extracting data from a website

I have an application which extracts data from a website and loads it into a server table. When I run the application first time in a day it is showing a popup and asking for Yes/No input. How to overcome this popup as I wanted to auto schedule the application and run it without manual intervention.
Public Sub Resolve_Date()
Dim XMLReq As MSXML2.XMLHTTP60 = New MSXML2.XMLHTTP60
Dim HTMLDoc = New mshtml.HTMLDocument
'Dim htmlbody As HtmlDocument.body = New HTML
Dim ObjXL As New Excel.Application
Dim Table As mshtml.IHTMLElement
Dim Tr As mshtml.IHTMLElement
Dim Tc As mshtml.IHTMLElement
Dim Trs As mshtml.IHTMLElementCollection
Dim URL As String
Dim x As Integer, y As Integer
URL = "https://tt.wiki.com/search?category=&assigned_group=3p-asin"
XMLReq.open("GET", URL, False) '--pop up is appearing here
XMLReq.send()
If XMLReq.status <> 200 Then
msgBox("Error" & vbNewLine & XMLReq.status & " - " & XMLReq.statusText)
Exit Sub
End If
Dim HTMLDoc1 As mshtml.IHTMLDocument = HTMLDoc
HTMLDoc1.write("<html><body>test</body></html>")
HTMLDoc1.close()
HTMLDoc = HTMLDoc1
HTMLDoc.body.innerHTML = XMLReq.responseText
''msgBox(HTMLDoc.body.innerHTML)
'MsgBox(HTMLDoc.body.innerHTML)
XMLReq = Nothing
Table = HTMLDoc.getElementById("search_results")
Trs = Table.getElementsByTagName("tr")
For Each Tr In Trs
--code to insert data into Table
Next Tr
I could do more if I knew what you were doing with the table... probably avoid the obsolte MsHtml API (HTMLDocument and friends) entirely. But with just the context we have, this is a rewrite that uses at least some more modern techniques and considerably simplifies the code.
Public Sub Resolve_Date()
Dim URL As String = "https://tt.wiki.com/search?category=&assigned_group=3p-asin"
Dim results As String = ""
Try
Using wc As New WebClient()
results = wc.DownloadString(URL)
End Using
Catch Ex As Exception
MsgBox($"Error{vbNewLine}{Ex.Message}")
Exit Sub
End Try
Dim HTMLDoc As New mshtml.HTMLDocument()
HTMLDoc.Write(results);
Dim Table As mshtml.IHTMLElement = HTMLDoc.getElementById("search_results")
Dim Trs As mshtml.IHTMLElementCollection = Table.getElementsByTagName("tr")
Dim ObjXL As New Excel.Application
Dim x As Integer, y As Integer
For Each Tr As mshtml.IHTMLElement In Trs
' code to insert data into Table
Next Tr
End Sub

VB.NET get a specific "href" by id

I need help to get start with my app.
I try to get HREF link from webpage without webbrowser.
I use HtmlAgilityPack but i cant get the spefic HREF:
<a id="ItemsList_file_0" title="HR9nqJCIqHex8niygKtwUHpdkjRGNaH22Oy54SPBmw.avi" href="http://dsa11.uverload.com/d/a012284e-1fd5-4317-82d3-9bf9e738f0a2/BIfmZ/0lOipBI/HR9nqJCIqHex8niygKtwUHpdkjRGNaH22Oy54SPBmw.avi" target="_blank">HR9nqJCIqHex8niygK..22Oy54SPBmw.avi</a><br />
i try this code .
Dim webreq As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://www.uverload.com/view/0lOipBI")
Dim webres As System.Net.HttpWebResponse = webreq.GetResponse
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(webres.GetResponseStream)
Dim docStr As String = sr.ReadToEnd
Dim HAPdoc As New HtmlAgilityPack.HtmlDocument
HAPdoc.LoadHtml(docStr)
Dim HAPnode As HtmlAgilityPack.HtmlNode
HAPnode = HAPdoc.GetElementbyId("ItemsList_file_0")
MsgBox(HAPnode.InnerText)
End Sub
give me nothing

Extract href text from website

How Can I extract href text from website?
<div class="ba by">**I want this text!**</div>
I try some solution, but doesn't work.
Dim myMatches As MatchCollection
Dim myRegex As New Regex("<div.*?class=""ba by"".*?>.*</div>", RegexOptions.Singleline)
Dim wc As New WebClient
Dim html As String = wc.DownloadString("http://somewebaddress.com")
TextBox1.Text = html
myMatches = myRegex.Matches(html)
MsgBox(html)
Dim successfulMatch As Match
For Each successfulMatch In myMatches
MsgBox(successfulMatch.Groups(1).ToString)
Next
or
Dim divs = WebBrowser1.Document.Body.GetElementsByTagName("div")
For Each d As HtmlElement In divs
If d.GetAttribute("class") = "ba by" Then
TextBox1.Text = d.InnerText
End If
Next
Thank you!
Instead of ...
Dim divs = WebBrowser1.Document.Body.GetElementsByTagName("div")
Try...
Dim anchors = WebBrowser1.Document.Body.GetElementsByTagName("a")
That should get you a list of all the "

how to access lotus notes view contents in .net using VB

I want to access contents of a catagorized view of lotu notes in .net.... can some one help me regarding this.. I am using interop.domino.dll.
Dim s As New Domino.NotesSession
Dim txt As String
Dim key() As String = {"abcd", "abcd"}
s.Initialize("")
Dim ldb As New NotesDatabase
ldb = s.GetDatabase("", "", False)
Dim vw As NotesView
vw = ldb.GetView("Project Module Wise Configurable Item")
vw.Refresh()
Dim entry As NotesViewEntry
Dim vc As NotesViewEntryCollection
vc = vw.GetAllEntriesByKey(key, False)
entry = vc.GetFirstEntry
While Not (entry Is Nothing)
txt = CStr(entry.Item)
entry = vc.GetNextEntry(entry)
ListBox1.Items.Add(txt)
End While
try:
Dim s As New Domino.NotesSession
s.Initialize("")
Dim ldb As New NotesDatabase
ldb = s.GetDatabase("", "", False)
Dim vw As NotesView
vw = ldb.GetView("Project Module Wise Configurable Item")
vw.Refresh()
Dim txt As String
Dim entry As NotesViewEntry
Dim vc As NotesViewEntryCollection
'declare the array
' ---- edited -----
Dim key(1) As variant
'----edited ---
key(0) = "abcd"
key(1) = "abcd"
'be carefull with the second parameter 'false'
vc = vw.GetAllEntriesByKey(key, False)
entry = vc.GetFirstEntry
While Not (entry Is Nothing)
txt = CStr(entry.Item)
entry = vc.GetNextEntry(entry)
ListBox1.Items.Add(txt)
End While
What worked for me: Declaring key as array of object.
Dim keys(0 To 1) As Object
keys(0) = "asdf"
keys(1) = "sgdk"
...