Как ускорить парсинг html? - Visual Basic .NET
Формулировка задачи:
Всем привет.
Столкнулся с такой проблемой, что парсинг html текста идет очень долго. Посмотрите пожалуйста, как можно оптимизировать код по скорости?
Листинг программы
- On Error Resume Next
- Dim int As Integer
- Dim fintext As String
- int = 0
- Dim html_text As String = WebBrowser1.Document.Body.InnerHtml
- Dim toggle As String
- Dim bool As Boolean
- Dim words As String() = html_text.Split("<SPAN")
- Dim strchar As Char
- For Each lines As String In words
- If bool = True Then
- If int < 5 Then
- bool = False
- End If
- GoTo plus
- End If
- strchar = lines(14)
- If strchar = "4" Or strchar = "5" Then
- plus:
- int = int + 1
- toggle = toggle + lines
- If int > 4 Then
- 'парсинг
- toggle = toggle + vbNewLine
- toggle = toggle.Replace("/SPAN>", "")
- toggle = toggle.Replace("SPAN class=Xb>", "")
- toggle = toggle.Replace("SPAN Class=Xc4>", "")
- toggle = toggle.Replace("SPAN class=Xc15>", "")
- toggle = toggle.Replace("SPAN class=", "")
- toggle = toggle.Replace("SPAN", "")
- toggle = toggle.Replace("Xc4", "")
- toggle = toggle.Replace("Xc0 Xb", "")
- toggle = toggle.Replace("<", "")
- toggle = toggle.Replace(">", "")
- Dim linez As String() = toggle.Split(vbNewLine)
- For Each linn As String In linez
- fintext = linn
- System.IO.File.WriteAllText("everyline.txt", fintext)
- Dim hash2 As HashSet(Of String) = New HashSet(Of String)
- Dim file2 As String() = IO.File.ReadAllLines("everyline.txt")
- For Each item2 As String In file2
- If item2.StartsWith(4) Then
- hash2.Add(item2)
- ElseIf item2.StartsWith(5)
- hash2.Add(item2)
- ElseIf item2.StartsWith(3)
- hash2.Add(item2)
- ElseIf linn.Contains("APP")
- hash2.Add(item2)
- ElseIf linn.Contains("$")
- hash2.Add(item2)
- End If
- Next
- IO.File.WriteAllLines("filtered.txt", hash2.ToList())
- Next
- End If
- bool = True
- End If
- Next
Решение задачи: «Как ускорить парсинг html?»
textual
Листинг программы
- For Each item2 As String In file2
- If item2.Contains("nks") Then
- Select Case item2(0)
- Case "3","4","5"
- hash2.Add(item2)
- End Select
- End If
- Next
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д