无法从Python的网店中抓取价格。

huangapple go评论73阅读模式
英文:

Can't seem to scrape off price from webshop in Python

问题

我正在尝试从不同的网店中爬取产品的价格。
我正在使用PythonrequestsBeautifulSoup来实现这个目标。

我想要爬取产品的价格,但是我在输出中看不到它出现。

我的代码如下:

response = requests.get('https://www.fritz-berger.de/suche?q=8710315990829')
soup = BeautifulSoup(response.content, 'html.parser')
print(soup.prettify())

通常情况下,我想使用正则表达式来获取价格,但是我看不到它的任何地方。我漏掉了什么吗?

英文:

I am trying to scrape of prices of products from different webshops.
I am doing this in Python with requests and BeautifulSoup.

I want to scrape a price of a product but I don't see it come up in the output.

My code looks like this:

response = requests.get('https://www.fritz-berger.de/suche?q=8710315990829')
    soup = BeautifulSoup(response.content, 'html.parser')
    print(soup.prettify())

Normally I want to get the price with regex but i don't see it anywhere. I am missing something?

答案1

得分: 0

你正在使用关于交付到荷兰(NL)而不是德国(DE)的特定设置,因此不会找到一个基本请求的结果来显示或重定向。因此,可以尝试使用XHR请求到其搜索API,并使用fv=NL来指定:

https://search.epoq.de/inbound-servletapi/getSearchResult?full&callback=jQuery360016688827514037174_1673258199659&tenantId=fritz-berger-de&sessionId=c29bb0e240b3a0c61f643287bc3362d&orderBy=&order=desc&limit=30&offset=0&locakey=&style=compact&format=json&nrf=&query=8710315990829&ff=e%3Awhitelist_country&fv=NL&_=1673258199660

这将非常适合具有这种特定焦点的提问新问题

尝试使用一个有效的链接或相关的搜索词,以获得一个有效的产品。你的链接将导致一个空的搜索结果页面。

import requests
from bs4 import BeautifulSoup

response = requests.get('https://www.fritz-berger.de/suche?q=452210')
soup = BeautifulSoup(response.content, 'html.parser')
soup.select_one('.current-price').get_text(strip=True).split('€')[0]

-> 5,99
英文:

EDIT

You are using a specific setting concerning delivery to NL not DE, so it won´t find a result for a basic request to show up or redirect. So may try the XHR request to their search api and use fv=NL to specify:

https://search.epoq.de/inbound-servletapi/getSearchResult?full&callback=jQuery360016688827514037174_1673258199659&tenantId=fritz-berger-de&sessionId=c29bb0e240b3a0c61f643287bc3362d&orderBy=&order=desc&limit=30&offset=0&locakey=&style=compact&format=json&nrf=&query=8710315990829&ff=e%3Awhitelist_country&fv=NL&_=1673258199660

This would be predestined for asking a new question with exact this focus.


Try to use a link or a relevant search term that is valid and leads to a product. Yours will lead to an empty search results page.

import requests
from bs4 import BeautifulSoup

response = requests.get('https://www.fritz-berger.de/suche?q=452210')
soup = BeautifulSoup(response.content, 'html.parser')
soup.select_one('.current-price').get_text(strip=True).split('€')[0]

-> 5,99

huangapple
  • 本文由 发表于 2023年1月9日 17:08:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75055082.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定