我做了一个代码:
from newspaper import Article
url = 'http://www.infomoney.com.br/mercados/acoes-e-indices/noticia/7345670/dow-jones-tem-nova-derrocada-puxa-ibovespa-para-segunda-semana'
a = Article(url, language='pt')
a.download()
a.parse()
print(a.text)但是我需要带html标签的文本,例如,我需要文本中的img标签。
发布于 2019-04-26 08:01:39
这个问题是一年前提出的,但有人可能会通过谷歌找到这个问题。
你可以使用"a.article_html“获取文章文本中的图片和其他html。
from newspaper import Article
a = Article('https://www.nytimes.com/2019/04/25/us/politics/joe-biden-anita-hill.html',
keep_article_html=True,
language='en')
a.download()
a.parse()
print(a.html) # This article's unchanged and raw HTML
print(a.article_html) # The HTML of this article's main node记住参数"keep_article_html=True“
发布于 2018-04-01 18:41:44
您可以通过html成员获取html。
from newspaper import Article
url = 'http://www.infomoney.com.br/mercados/acoes-e-indices/noticia/7345670/dow-jones-tem-nova-derrocada-puxa-ibovespa-para-segunda-semana'
a = Article(url, language='pt')
a.download()
a.parse()
print(a.text)
html = a.html
print(html)https://stackoverflow.com/questions/49458594
复制相似问题