在python中解析聊天日志,当前使用BeautifulSoup

在python中解析聊天日志,当前使用BeautifulSoup,python,html-parsing,chat,Python,Html Parsing,Chat,我在使用Python 2.7解析IM聊天日志时遇到一些问题。我目前正在使用beautifulsou.get\u text。这通常有效,但有时会掩盖有趣的东西。例如: <font color="#A82F2F"><font size="2">(3/11/2016 3:11:57 PM)</font> <b>user name:</b></font> <html xmlns='http://jabber.org/proto

我在使用Python 2.7解析IM聊天日志时遇到一些问题。我目前正在使用
beautifulsou.get\u text
。这通常有效,但有时会掩盖有趣的东西。例如:

<font color="#A82F2F"><font size="2">(3/11/2016 3:11:57 PM)</font> <b>user name:</b></font> <html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'><p>Have you posted the key to <a href="https://___.edu/sshkeys/?">https://___.edu/sshkeys/?</a></p></body></html><br/>
(2016年11月3日下午3:11:57)用户名:你把钥匙贴到
在本例中,我得到了
是否已将密钥发布到
部分,但它去掉了
https:\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
部分

大多数(并非所有)行的格式都相同。i、 日期、时间、用户、有趣的东西

有没有更好的解析方法来获取文本和所有有趣的内容?

您可以利用:


取决于你想如何输出这些信息,你必须或多或少地变得聪明。

这对我来说很有用-获取
(3/11/2016 3:11:57 PM)用户名:你发布了https://___.edu/sshkeys/?
使用
获取文本()
时。把你目前掌握的代码贴出来。谢谢,嗯。我不太喜欢:
soup=BeautifulSoup(I,“lxml”)soupy=soup.get_text()
for anchor in soup.find_all('a', href=True):
    print("The anchor url={} text={}".format(anchor['href'], anchor['text'])