def get_name(uid):
url = 'https://www.airbnb.com/users/show/' + uid + '?locale=en'
cj = cookielib.MozillaCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
req = urllib2.Request(url)
req.add_header("User-agent", 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) \
Chrome/50.0.2661.102 Safari/537.36')
try:
response = opener.open(req, timeout=10)
except Exception as inst:
print type(inst)
print inst.args
print inst
print('-----fail to get name data')
return ''
data = response.read()
name = re.findall('Hey, I’m (.*?)!', data)
if len(name):
return name[0]
else:
return ''
airbnb_superhost_photo_crawler.py 文件源码
python
阅读 17
收藏 0
点赞 0
评论 0
评论列表
文章目录