是否可以通过请求找到此链接文本?

时间:2017-02-23 09:36:29

标签: python beautifulsoup python-requests

在网址https://www.airbnb.com/rooms/3093543处,有一张地图加载在页面底部附近,其中包含一个显示Presidio的“邻居”框。它存储在标记<a href="/locations/neighborhoods/479">Presidio</a>

我正试着用它来解决这个问题:

profile = BeautifulSoup(requests.get("https://www.airbnb.com/rooms/3093543").content, "html.parser")

print profile.select('div[id="hover-card"]')[0].find('a').text 
    # div[id="hover-card"] is not found

我不确定这是一个动态变量,只能用另一个模块检索,或者是否可以获取请求。

1 个答案:

答案 0 :(得分:2)

您可以通过其他元素获取该数据。 试试这个:

profile =  BeautifulSoup(requests.get("https://www.airbnb.com/rooms/3093543").content, "html.parser")
print profile.select('meta[id="_bootstrap-neighborhood_card"]')[0]

如果需要,请通过以下方式请求地图:

https://www.airbnb.pt/locations/api/neighborhood_tiles.json?ids%5B%5D=ID

上述网址中的ID由第一次打印中的neighborhood_basic_info属性提供。