【发布时间】:2018-10-20 22:34:00
【问题描述】:
我正在尝试使用 beautifulsoup4 从网站上抓取数据并仅检索 html 标签之间的信息以放入 excel 文档中,目前我只能从页面中获取整个 html 数据。
import sys
import urllib3
import xlsxwriter
import lxml
page = requests.get('genericurlhere.com')
soup = BeautifulSoup(page.text, 'html.parser')
f = csv.writer(open('web_scrape.csv', 'w'))
f.writerow(['Item', 'Description'])
heading = soup.find_all("h4", class_="list-group-item-heading")
print(heading)
print('-------------------')
desc = soup.find_all("p", class_='list-group-item-text')
print(desc)
【问题讨论】:
标签: python beautifulsoup html-parsing