我的代码:
url="https://www.nytimes.com/reuters/2018/04/05/business/05reuters-usa-
tradechina-ip.html"
html = urlopen(url).read()
soup = BeautifulSoup(html,'html.parser')
def text_from_html(body):
texts = soup.find_all('p',class_="story-body-text story-content")
return texts
print(text_from_html(html)[0])
如何只打印文本而不打印其他信息?
答案 0 :(得分:1)
print(text_from_html(html)[0].text)
将完成工作