【问题标题】:Need to extract text messages out of an HTML document需要从 HTML 文档中提取文本消息
【发布时间】:2015-05-10 03:21:54
【问题描述】:

您好,我有一个很长的 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 vb.net string chat data-extraction


【解决方案1】:

如果其他人对这样的操作感兴趣,我已经设法通过将 HTML 代码应用到另一个网络浏览器然后使用Document.Body.InnerHtml 属性在富文本框中获取文本输出来简化该过程,所以我可以轻松处理处理文本而不是处理 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)

这是我最接近的。如果您有更好的答案,请发布。

【讨论】:

    猜你喜欢
    • 2021-10-22
    • 2011-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-12
    • 2021-08-08
    • 2012-05-09
    • 2013-12-22
    相关资源
    最近更新 更多