网络刮痧Nytimes

时间:2018-04-06 02:21:34

标签: python web-scraping beautifulsoup

我的代码:

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])

我的输出: enter image description here

如何只打印文本而不打印其他信息?

1 个答案:

答案 0 :(得分:1)

print(text_from_html(html)[0].text)

将完成工作