【发布时间】:2020-07-03 06:58:58
【问题描述】:
我有网页-https://dmesupplyusa.com/mobility/bariatric-rollator-with-8-wheels.html 这里有一个详细信息下的规范列表,我想提取为表格,即规范类别作为标题,规范值作为下一行。我如何在 python 中使用 beautifulsoup 做到这一点?
【问题讨论】:
标签: python web-scraping beautifulsoup html-lists
我有网页-https://dmesupplyusa.com/mobility/bariatric-rollator-with-8-wheels.html 这里有一个详细信息下的规范列表,我想提取为表格,即规范类别作为标题,规范值作为下一行。我如何在 python 中使用 beautifulsoup 做到这一点?
【问题讨论】:
标签: python web-scraping beautifulsoup html-lists
import requests
import pandas as pd
from bs4 import BeautifulSoup as bs
page = requests.get("https://dmesupplyusa.com/mobility/bariatric-rollator-with-8-wheels.html").content #Read Page source
page = bs(page) # Create Beautifulsoup object
data = page.find_all('strong', string="Product Specifications")[0].find_next('ul').text.strip().split('\n') # Extract requireed information
data = dict([zip(i.split(":")) for i in data])
df = pd.DataFrame(data).T
我希望这就是你要找的。p>
【讨论】: