我需要从许多网站上搜集汽车排名
例如:
https://www.kbb.com/articles/best-cars/10-best-used-cars-under-10000/
https://www.autoguide.com/auto-news/2019/10/top-10-best-cars-for-snow.html
道奇充电器AWD 斯巴鲁内陆 日产Altima AWD ...
我很难在网站上发现排名,因为它们都有点不同。我的目标基本上是有一个脚本,可以自动检测排名,并在任何给定的汽车网站上以相当高的精度检索我需要的数据(排名中的品牌+汽车型号)
我想收集的数据(排名中的品牌+车型)有时在H2、H3或H4中,有时在链接中。。。 有时它被写为“1.Brand1 Model1,2.Brand2 Model2…” 有时“品牌1模式1,品牌2模式2…” 这取决于
我正在用Python和BeautifulSoup进行这项工作
什么是好方法
编辑:
明确地说,我正在努力分析数据,而不是去刮取数据(见下面的评论)。 但为了说明这一点,以下是我如何处理上述第一个示例:
for url in urls:
req = requests.get(url)
soup = BeautifulSoup(req.text, "lxml")
for sub_heading in soup.find_all('h2'):
if str(1) + ". " in sub_heading.text and "11." not in sub_heading.text: #filter applied to keep only strings starting with "1. "
list_url.append(url)
print(list_sub_heading)
结果: ['1.2011丰田凯美瑞']
输出:
re
版本:输出:
相关问题 更多 >
编程相关推荐