【问题标题】:Beautifulsoup - Remove HTML tagsBeautifulsoup - 删除 HTML 标签
【发布时间】:2019-12-18 15:02:29
【问题描述】:

我正在尝试从“个人资料”汤中去除所有 HTML 标签,我无法执行“.text.strip()”操作,因为它是一个列表,如下面的代码所示

import requests 
from bs4 import BeautifulSoup
from pprint import pprint 

page = requests.get("https://web.archive.org/web/20121007172955/http://www.nga.gov/collection/anZ1.htm").text
soup = BeautifulSoup(company_page, "html.parser")

info = {}
info['Profile'] = soup.select('div.text-desc-members')

pprint(info)

【问题讨论】:

  • 无法执行“.text.strip()”操作,因为它是一个列表问题解决了,不是吗?

标签: python html python-3.x web-scraping beautifulsoup


【解决方案1】:

只需遍历该列表:

import requests 
from bs4 import BeautifulSoup
from pprint import pprint 

page = requests.get("https://web.archive.org/web/20121007172955/http://www.nga.gov/collection/anZ1.htm").text
soup = BeautifulSoup(page, "html.parser")

info = {}
info['Profile'] = soup.select('div.text-desc-members')


for item in info['Profile']:
    pprint(item.text.strip())

【讨论】:

猜你喜欢
  • 2020-03-08
  • 2011-02-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-19
  • 1970-01-01
  • 1970-01-01
  • 2020-02-26
  • 2011-04-04
相关资源
最近更新 更多