簡體   English   中英

似乎無法從 Python 的網上商店刮掉價格

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

我正在嘗試從不同的網上商店中獲取產品的價格。 我在Python中使用requestsBeautifulSoup執行此操作。

我想獲取產品的價格,但我沒有看到它出現在 output 中。

我的代碼如下所示:

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

通常我想用regex獲得價格,但我在任何地方都看不到它。 我錯過了什么?

編輯

您正在使用有關交付到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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM