【发布时间】:2018-01-08 08:23:45
【问题描述】:
我想从给定网站中提取所有主题标签: 例如,“我喜欢#stack overflow,因为#people 非常#helpful!” 这应该将 3 个主题标签拉到一个表中。 在我的目标网站中,有一个带有#tag 描述的表格 所以我们可以找到#love 这个标签谈论爱
这是我的作品:
#import the library used to query a website
import urllib2
#specify the url
wiki = "https://www.symplur.com/healthcare-hashtags/tweet-chats/all"
#Query the website and return the html to the variable 'page'
page = urllib2.urlopen(wiki)
#import the Beautiful soup functions to parse the data returned from the
website
from bs4 import BeautifulSoup
#Parse the html in the 'page' variable, and store it in Beautiful Soup
format
soup = BeautifulSoup(page, "lxml")
print soup.prettify()
s = soup.get_text()
import re
re.findall("#(\w+)", s)
我的输出有问题: 第一个是输出如下所示: [u'eeeeee', u'333333', 你'222222', 你'222222', 你'222222', 你'222222', 你'222222', 你'222222', 你'222222', u'AASTGrandRoundsacute'
输出将 Hashtag 与描述中的第一个单词连接起来。如果我与我在输出为“lovethis”之前调用的示例进行比较。
如何只提取主题标签后的一个单词。
谢谢
【问题讨论】:
-
“u”实际上并不存在。它由python显示,告诉你它旁边的字符串在unicode中。 stackoverflow.com/a/599653/3072566
标签: python html beautifulsoup lxml hashtag