Python Webscrapping:需要帮助从span html标签获取数据值

问题描述 投票:-2回答:1

我目前正在尝试获取四舍五入后的美元的数据测试值,但我一直收到错误NoneType,我只是想知道如何解决这个问题:DSnippet of website html code of the part i want to scrape

这是我当前的代码:

import requests
from bs4 import BeautifulSoup

url = 'https://www.priceline.com/m/fly/search/YYZ-YUL-20200214/?cabin-class=ECO&no-date-search=false&search-type=11&num-adults=1&refclickid=https%3A%2F%2Fwww.google.com%2F'

page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
price = soup.find('span', attrs={'data-test': 'rounded-dollars'})
print(price)
python html web-scraping beautifulsoup python-requests
1个回答
0
投票

如果您右键单击该页面并查看页面源,则会发现您要查找的代码不存在于页面中。同样,如果您这样做:

response = requests.get(url)
print("DisplayPrice" in response.content)

您会发现,所要查找的代码未在get请求中返回。如@ andrej-kesely所述,您要查找的数据是通过javascript注入的,因此您可能需要模仿其发出的请求才能获取数据。

此外,尽管您确实包括了代码示例的图像,但是对于那些帮助您简单地查看代码的人员而言,要容易得多,因此,如果您提交其他问题,请使用堆栈溢出示例的语法并直接输入代码。

© www.soinside.com 2019 - 2024. All rights reserved.