【发布时间】:2017-09-06 19:19:25
【问题描述】:
我正在学习爬虫,并正在 Airbnb (here's the page) 上尝试。当我使用 Google Chrome 检查其中一张家庭图片时,我看到了:
我无法让我的脚本返回代表图中内容的 HTML(例如列表的链接)。初步尝试:
import requests
url = "https://www.airbnb.co.uk/s/Rome/homes?checkin=2017-11-12&checkout=2017-11-19"
landing = requests.get(url)
print landing.content.find("rooms/")
这只是返回一个-1(即rooms/不在HTML中)。
然后一些研究提出了关于“标题”的想法,因此 Airbnb 不知道我是一个脚本(代码是复制/粘贴的,因为我真的不明白这些标题的作用)。其他人建议使用 urllib 代替。所以最近的尝试是:
from urllib2 import Request,urlopen
user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36'
headers = { 'User-Agent' : user_agent }
url = "https://www.airbnb.co.uk/s/Rome/homes?checkin=2017-11-12&checkout=2017-11-19"
req = Request(url,None,headers)
landing = urlopen(req)
print landing.read().find('rooms/')
这也返回一个 -1。
非常感谢任何想法。我正在使用 Python 2.7 (Windows)。
【问题讨论】:
标签: python python-2.7 web-scraping urllib2