【问题标题】:Retrive html tag content using beautifulSoup使用 beautifulSoup 检索 html 标签内容
【发布时间】:2021-01-27 11:23:10
【问题描述】:

我正在尝试使用 python 获取网站文章的纯文本。我听说过 BeautifulSoup 库,但是如何检索 html 页面中的特定标签?

这就是我所做的:

base_url = 'http://www.nytimes.com'
r = requests.get(base_url)
soup = BeautifulSoup(r.text, "html.parser")

【问题讨论】:

标签: python beautifulsoup python-requests


【解决方案1】:

看这个:

import bs4 as bs
import requests as rq

html = rq.get('site.com')

s = bs.BeautifulSoup(html.text, features="html.parser")
div = s.find('div', {'class': 'yourclass'}) # or id

print(str(div.text)) # print text

【讨论】:

  • Ciao Giacomo,grazie mille,funziona
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-05-15
  • 1970-01-01
  • 1970-01-01
  • 2014-03-27
  • 2014-05-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多