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)