python爬取穷游网城市名称和去过的人数
import requests
from lxml import etree
def info(url):
headers={
'user-agent': ''
}
response=requests.get(url,headers=headers)
soup=etree.HTML(response.text)
place=soup.xpath('/html/body/div[5]/div/div[1]/ul/li')
for i in place:
local=i.xpath('./h3/a/text()')[0].strip()
count=''.join(i.xpath('./p[2]/text()'))
f = open('穷游网.csv', 'a', encoding='utf8')
f.write('{},{}\n'.format(local,count))
f.close()
if __name__ == '__main__':
for i in range(4):
url='https://place.qyer.com/china/citylist-0-0-{}/'.format(i)
info(url)