爬虫手机端 headers
from bs4 import BeautifulSoup
import requests
headers = {
'User-Agent':'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1',
}
url = 'http://www.tripadvisor.cn/Attractions-g294212-Activities-c47-oa190-Beijing.html'
mb_data = requests.get(url,headers=headers)
soup = BeautifulSoup(mb_data.text,'lxml')
titles = soup.select('.title.titleLLR > .location')
names = soup.select('.overflowEllipsis > .rs.popularityLLR.overflowEllipsis')
imgs = soup.select('div.thumb.thumbLLR.soThumb > img')
for title,name,img in zip(titles,names,imgs):
data = {
'title':title.get_text(),
'name':name.get_text(),
'img':img.get('src')
}
print(data)