使用 Python 从网站的搜索栏中获取价格 [英] Scraping pricing off a search bar from a website with Python
本文介绍了使用 Python 从网站的搜索栏中获取价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个要从搜索栏中查找的零件编号列表:https://www.partsfinder.com/catalog/preview?q=0119000230this 网站.
I have a list of part numbers to be looked up from the search bar on: https://www.partsfinder.com/catalog/preview?q=0119000230this site.
我想从结果中收集价格.
I want to collect the prices off the results.
这是我整理的内容,但我不知道该从哪里开始:
Here's what I put up together but I'm not sure where to go from here:
import requests
from bs4 import BeautifulSoup
r = requests.get('https://www.partsfinder.com/catalog/preview?q=0119000230')
soup = BeautifulSoup(r.text, 'html.parser')
resultsRow = soup.find_all('a', {'class': 'search_result_row'})
results = []
感谢任何帮助,谢谢!
推荐答案
内容通过 xhr POST 请求动态加载.刷新页面时,您可以在浏览器的开发工具中看到这一点.您可以将请求最小化为以下内容:
Content is dynamically loaded via xhr POST request. You can see this in the dev tools of browser when refreshing the page. You can minimize the request to the following:
import requests
data = {"partOptionFilter":{"PartNumber":"0119000230","AlternativeOemId":"17155"}}
r = requests.post('https://www.partsfinder.com/Catalog/Service/GetPartOptions',json=data).json()
print(r['Data']['PartOptions'][0]['YourPrice'])
这篇关于使用 Python 从网站的搜索栏中获取价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文