使用python lxm刮取airbnb

2024-09-29 02:24:53 发布

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

我正在尝试在airbnb列表中查找节点。节点是

< div class="col-md-3 text-muted" data-reactid=".2e7if3twveo.0.0.0.0.1.6.0">< span data-reactid=".2e7if3twveo.0.0.0.0.1.6.0.0">The Space< /span> /div> 

^{pr2}$

不知何故“空间”是不可恢复的。在


Tags: thetextdiv列表data节点colspace
1条回答
网友
1楼 · 发布于 2024-09-29 02:24:53

这对我很有用:我使用beauthoulsoup通过类属性获取div,然后循环查找正确的div。在

import requests
from bs4 import BeautifulSoup

url = 'https://www.airbnb.com/rooms/5711344'
html = requests.get(url)
soup = BeautifulSoup(html.text, 'html.parser')
divs = soup.find_all('div', attrs={'class': 'col-md-3 text-muted'})
for div in divs:
    space = div.find('span').text.strip()
    if space == "The Space":
        print(space)

相关问题 更多 >