Python机票报废网站

2024-04-24 08:03:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图用python脚本提取有关机票价格的信息。请看图片:

Inspect element

我想解析所有的价格(比如树底部的“121”)。我已经构建了一个简单的脚本,我的问题是我不知道如何从页面的“inspect元素”后面的代码中获得正确的部分。我的代码如下:

import urllib3
from bs4 import BeautifulSoup as BS

http = urllib3.PoolManager()


ULR = "https://greatescape.co/?datesType=oneway&dateRangeType=exact&departDate=2019-08-19&origin=EAP&originType=city&continent=europe&flightType=3&city=WAW"
response = http.request('GET', URL)
soup = BS(response.data, "html.parser")

body = soup.find('body')
__next = body.find('div', {'id':'__next'})
ui_container = __next.find('div', {'class':'ui-container'})
bottom_container_root = ui_container.find('div', {'class':'bottom-container-root'})

print(bottom_container_root)

问题是我被困在ui-container的水平。bottom-container-root是空变量,尽管它是ui-container下的直接子变量。有人能告诉我如何正确解析这棵树吗?你知道吗

我没有在网络报废的经验,但它碰巧是一个更大的工作流程,我正在建设的一步。你知道吗


Tags: 代码importdiv脚本httpuicitybs
1条回答
网友
1楼 · 发布于 2024-04-24 08:03:23

.find_next_siblings.next_element在浏览容器时非常有用。你知道吗

下面是一些示例用法。你知道吗

from bs4 import BeautifulSoup

html = open("small.html").read()
soup = BeautifulSoup(html)

print soup.head.next_element
print soup.head.next_element.next_element

相关问题 更多 >