【发布时间】:2019-11-07 12:04:40
【问题描述】:
我无法从该页面打印出文本,因为 BeautifulSoup 没有选择跨度类或部分类标签。我想从 Motley Fool 中提取文本,然后逐句解析。
到目前为止,当它偶尔拉入文本时,句子解析工作,然而,美丽的汤只是偶尔拉入文本。
from textblob import TextBlob
from html.parser import HTMLParser
import re
def news():
# the target we want to open
url = dataframe_url
#open with GET method
resp=requests.get(url)
#http_respone 200 means OK status
if resp.status_code==200:
soup = BeautifulSoup(resp.text,"html.parser")
#l = soup.find("span",attrs={'class':"article-content"})
l = soup.find("section",attrs={'class':"usmf-new article-body"})
#print ('\n-----\n'.join(tokenizer.tokenize(l.text)))
textlist.extend(tokenizer.tokenize(l.text))
else:
print("Error")
【问题讨论】:
-
你能举几个没有被拉出的句子的例子吗?另外,您是否尝试过
soup.find_all()而不是soup.find()? -
我正在尝试从 url 中提取整个脚本文本,这是 html 中的一个例句:
大家好。欢迎参加埃克森美孚公司 2019 年第一季度财报电话会议。正在录制今天的通话。
标签: python beautifulsoup tags html-parsing textblob