我试图使用Python中的BeautifulSoup收集webdata数据。我正专门尝试提取不同类型的汽车特征。例如,在下面粘贴的html代码中,我试图提取“远程启动”、“导航系统”和“加热方向盘”作为“方便”功能。有谁能告诉我如何提取和存储每个这类类别的特征吗?

发布于 2019-10-26 12:14:46
以下是一种方法:
import bs4
your_source_code = "<html>..."
soup = bs4.BeautifulSoup(your_source_code, "html.parser")
result = {}
for group in soup.find_all("div", {"class": "details-feature-list--normalized-features"}):
result[group.find("h2", {"class": "cui-heading-2"}).text] = [itm.text for itm in group.find_all("li", {"class": "details-feature-list__item"})]结果是这样的:
{"Convenience": ["Remote Start", "Navigation System", "Heated Steering Wheel"]}
https://stackoverflow.com/questions/58570551
复制相似问题