爬虫-猫途鹰

from bs4 import BeautifulSoup
import requests
url = 'https://www.tripadvisor.cn/'
wb_data = requests.get(url)
soup = BeautifulSoup(wb_data.text,'lxml')
for i in soup.select('li'):
        if len(i.select('.ranking'))>0:
            sort=i.select('.ranking')[0].text #排名
            country=i.select('.countryName')[0].text #国家
            city=i.select('.cityName')[0].text #城市
            hotel=i.select('.hotelsCount')[0].text #酒店数
            toury=i.select('.attractionCount')[0].text #景点数
            eat=i.select('.eateryCount')[0].text #餐厅数
            review=i.select('.reviewTitle')[0].text  #印象
            print(sort,country,city,review,hotel,toury,eat)

 

posted on 2017-09-28 14:05  01-李嘉秀  阅读(247)  评论(0编辑  收藏  举报

导航