爬取价格

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

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 = &#39;https://r.pl/api/v4.1/wyszukiwarka/wyszukaj-kalkulator&#39;

payload = {
	&quot;CzyAvg&quot;: True,
	&quot;DatyUrodzenia&quot;: [
		&quot;1993-03-12&quot;,
		&quot;1993-03-12&quot;
	],
	&quot;Dlugosc&quot;: 15,
	&quot;HotelNaPrzedluzenieUrl&quot;: &quot;riu-tikida-palace-taghazout&quot;,
	&quot;HotelUrl&quot;: &quot;zakwaterowanie-mrg&quot;,
	&quot;Iata&quot;: &quot;WAW&quot;,
	&quot;LiczbaPokoi&quot;: 1,
	&quot;ProduktUrl&quot;: &quot;mozaika-polnocy&quot;,
	&quot;TerminWyjazdu&quot;: &quot;2023-09-01&quot;
}

data = requests.post(api_url, json=payload).json()

#to print all data uncomment next line:
#print(json.dumps(data, indent=4))

print(data[&#39;Wybrany&#39;][&#39;Cena&#39;])

Prints:

8253

huangapple
  • 本文由 发表于 2023年3月12日 18:24:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75712478.html
匿名

发表评论

匿名网友

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

确定