我关注了一些帖子,试图做到这一点。我有一个HTML页面作为文件。我尝试提取包含字符串的行并将该行定义为单独的字符串,以便我可以使用substring命令从该行(现在是字符串)中进一步提取数据。
到目前为止,我唯一得到的是将整个文本作为Foundit字符串。
Dim Searchstring As String
Searchstring = RichTextBox1.Text
Dim SearchStringPlus = Regex.Replace(Searchstring, "\s+", "+")
Dim SearchHTML As String
Dim WebClient1 As New Net.WebClient
SearchHTML = WebClient1.DownloadString("https://www.imdb.com/find?ref_=nv_sr_fn&q=" & SearchStringPlus & "&s=tt")
Dim SearchIndex As String = "<td class=""primary_photo""> <a href=""/title/tt"
Dim iSearch As System.IO.StreamWriter
iSearch = My.Computer.FileSystem.OpenTextFileWriter("iSearch.txt", False)
iSearch.WriteLine(SearchHTML)
iSearch.Close()
Dim SearchHTMLR As IO.StreamReader
SearchHTMLR = My.Computer.FileSystem.OpenTextFileReader("iSearch.txt")
Dim FoundLine() As String = SearchHTMLR.ReadToEnd.Split(Environment.NewLine)
Dim foundit As String = FoundLine.FirstOrDefault(Function(x) x.Contains(SearchIndex))
SearchHTMLR.Close()
iSearch = My.Computer.FileSystem.OpenTextFileWriter("iSearch.txt", False)
iSearch.WriteLine(foundit)
iSearch.Close()
Process.Start("notepad++.exe", "iSearch.txt")
答案 0 :(得分:0)
现在您将这些行作为foundlines()
尝试一下,告诉我是否可行
For each line in foundlines()
If line.contains("string")
Dim str as string = line
Next
不要使您的代码复杂化,只需抓住这些行,然后使用vb.newline将它们分开到foundlines()中,循环遍历每行并搜索包含该字符串的行。