2017-02-23 69 views
1

在URL 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

不,这是不可能的。它是动态加载的,你可以通过在浏览器中禁用javascript来检查那样的事情。试试例如硒。 –

回答

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 

凡在上述URL中的ID是通过在第一打印的neighborhood_basic_info属性给出 尝试此。

相关问题