需要从 HTML 文档中提取文本消息
Need to extract text messages out of an HTML document
你好,我有一个很长的HTML文档,这只是我感兴趣的部分:
<iframe class="goog-te-menu-frame skiptranslate" src="javascript:void(0)" frameborder="0" style="display: none; visibility: visible;"></iframe><div class="chatbox3"><div class="chatbox2"><div class="chatbox"><div class="logwrapper" style="top: 89px; margin-right: 168px;"><div class="logbox"><div style="position: relative; min-height: 100%;"><div class="logitem"><p class="statuslog">You're now chatting with a random stranger. Say hi!</p></div><div class="logitem"><p class="strangermsg"><strong class="msgsource">Stranger:</strong> <span>hii there</span></p></div><div class="logitem"><p class="strangermsg"><strong class="msgsource">Stranger:</strong> <span>nice to meet you</span></p></div><div class="logitem"><p class="strangermsg"><strong class="msgsource">Stranger:</strong> <span>this is a text</span></p></div><div class="logitem"><p class="youmsg"><strong class="msgsource">You:</strong> <span>this text should not be taken</span></p></div><div class="logitem"><p class="statuslog">Stranger has disconnected.</p></div><div class="logitem"><div class="statuslog">
输出如下:
您正在和一个随机的陌生人聊天。打声招呼!
陌生人:你好陌生人:很高兴见到你陌生人:这是一条短信你:这条短信不应该被接受陌生人已断开连接。
我想将Stranger发送的所有消息提取成字符串(Visual Basic),忽略我发送的消息和系统消息,例如You are now chatting with a random stranger. Sai hi!
和Stranger has disconnected.
我不知道我应该如何处理这个问题并需要帮助,谢谢。
如果其他人对这样的操作感兴趣,我已经设法通过将 HTML 代码应用于另一个网络浏览器然后使用 Document.Body.InnerHtml
属性 来简化该过程richtextbox 中的文本输出,因此我可以轻松处理文本而不是处理 HTML 代码。
OmegleHTML.Text = Omegle.Document.Body.InnerHtml
WebBrowser1.Document.Body.InnerHtml = OmegleHTML.Text
Log.Text = WebBrowser1.Document.Body.OuterText
我还使用了以下代码来删除聊天记录前的所有无关文本:
Dim SInd, Eind As Integer
SInd = 0
Eind = Log.Text.IndexOf("You're now chatting with a random stranger. Say hi!")
Log.Text = Log.Text.Remove(SInd, Eind)
这是我得到的最接近的。如果你有更好的答案,请post吧。
你好,我有一个很长的HTML文档,这只是我感兴趣的部分:
<iframe class="goog-te-menu-frame skiptranslate" src="javascript:void(0)" frameborder="0" style="display: none; visibility: visible;"></iframe><div class="chatbox3"><div class="chatbox2"><div class="chatbox"><div class="logwrapper" style="top: 89px; margin-right: 168px;"><div class="logbox"><div style="position: relative; min-height: 100%;"><div class="logitem"><p class="statuslog">You're now chatting with a random stranger. Say hi!</p></div><div class="logitem"><p class="strangermsg"><strong class="msgsource">Stranger:</strong> <span>hii there</span></p></div><div class="logitem"><p class="strangermsg"><strong class="msgsource">Stranger:</strong> <span>nice to meet you</span></p></div><div class="logitem"><p class="strangermsg"><strong class="msgsource">Stranger:</strong> <span>this is a text</span></p></div><div class="logitem"><p class="youmsg"><strong class="msgsource">You:</strong> <span>this text should not be taken</span></p></div><div class="logitem"><p class="statuslog">Stranger has disconnected.</p></div><div class="logitem"><div class="statuslog">
输出如下:
您正在和一个随机的陌生人聊天。打声招呼!
陌生人:你好陌生人:很高兴见到你陌生人:这是一条短信你:这条短信不应该被接受陌生人已断开连接。我想将Stranger发送的所有消息提取成字符串(Visual Basic),忽略我发送的消息和系统消息,例如You are now chatting with a random stranger. Sai hi!
和Stranger has disconnected.
我不知道我应该如何处理这个问题并需要帮助,谢谢。
如果其他人对这样的操作感兴趣,我已经设法通过将 HTML 代码应用于另一个网络浏览器然后使用 Document.Body.InnerHtml
属性 来简化该过程richtextbox 中的文本输出,因此我可以轻松处理文本而不是处理 HTML 代码。
OmegleHTML.Text = Omegle.Document.Body.InnerHtml
WebBrowser1.Document.Body.InnerHtml = OmegleHTML.Text
Log.Text = WebBrowser1.Document.Body.OuterText
我还使用了以下代码来删除聊天记录前的所有无关文本:
Dim SInd, Eind As Integer
SInd = 0
Eind = Log.Text.IndexOf("You're now chatting with a random stranger. Say hi!")
Log.Text = Log.Text.Remove(SInd, Eind)
这是我得到的最接近的。如果你有更好的答案,请post吧。