英文:
Wen scrapping price
问题
我正在尝试从链接holidays<p>。
我尝试使用[tag:Python]中的[tag:BeautifulSoup]来完成这个任务,但失败了。接下来,我尝试使用[https://stackoverflow.com/questions/71280231/beautiful-soup-findall-doesnt-find-value]中提到的解决方案,但也失败了。
是否有其他方法可以实现这个目标?
英文:
I'm trying to webscrap the total price from link holidays<p>
I 've tried to use [tag:BeautifulSoup] from [tag:Python] to do this but it failed, next i have tried to use [https://stackoverflow.com/questions/71280231/beautiful-soup-findall-doesnt-find-value] solution but it failed too.
Is it possible to do this by any other methods ?
答案1
得分: 1
价格和其他信息是通过Javascript从不同的URL加载的(你应该在Web开发者工具的Network标签中看到这个URL):
import json
import requests
api_url = 'https://r.pl/api/v4.1/wyszukiwarka/wyszukaj-kalkulator'
payload = {
"CzyAvg": True,
"DatyUrodzenia": [
"1993-03-12",
"1993-03-12"
],
"Dlugosc": 15,
"HotelNaPrzedluzenieUrl": "riu-tikida-palace-taghazout",
"HotelUrl": "zakwaterowanie-mrg",
"Iata": "WAW",
"LiczbaPokoi": 1,
"ProduktUrl": "mozaika-polnocy",
"TerminWyjazdu": "2023-09-01"
}
data = requests.post(api_url, json=payload).json()
#要打印所有数据,请取消下一行的注释:
#print(json.dumps(data, indent=4))
print(data['Wybrany']['Cena'])
英文:
The price and other info is loaded with Javascript from different URL (You should see this URL in Web Developer Tools -> Network Tab):
import json
import requests
api_url = 'https://r.pl/api/v4.1/wyszukiwarka/wyszukaj-kalkulator'
payload = {
"CzyAvg": True,
"DatyUrodzenia": [
"1993-03-12",
"1993-03-12"
],
"Dlugosc": 15,
"HotelNaPrzedluzenieUrl": "riu-tikida-palace-taghazout",
"HotelUrl": "zakwaterowanie-mrg",
"Iata": "WAW",
"LiczbaPokoi": 1,
"ProduktUrl": "mozaika-polnocy",
"TerminWyjazdu": "2023-09-01"
}
data = requests.post(api_url, json=payload).json()
#to print all data uncomment next line:
#print(json.dumps(data, indent=4))
print(data['Wybrany']['Cena'])
Prints:
8253
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论