第五关电影票房数据爬取

master
hnu202009070122 3 years ago
parent ae63ce5f7c
commit 553879305d

@ -0,0 +1,24 @@
import requests
from lxml import etree
headers={
'Cookie': 'Hm_lvt_e71d0b417f75981e161a94970becbb1b=1623642627; DIDA642a4585eb3d6e32fdaa37b44468fb6c=cbpkv0aghe6jjfjcgnt6kta7g6; remember=0; time=MTEzNTI2LjIxNjM0Mi4xMDI4MTYuMTA3MTAwLjExMTM4NC4yMDc3NzQuMTE5OTUyLjExMTM4NC4xMDQ5NTguMTE1NjY4LjEwNzEwMC4xMDkyNDIuMTE1NjY4LjExMTM4NC4xMDkyNDIuMTAyODE2LjExNzgxMC4xMTM1MjYuMA%3D%3D; Hm_lpvt_e71d0b417f75981e161a94970becbb1b=1623643075',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36 Edg/91.0.864.48'
}
for i in range(0,11):
url = 'http://58921.com/alltime?page={}'.format(i)
wood=requests.get(url=url,headers=headers)
wood.encoding=wood.apparent_encoding
# print(wood)
word=etree.HTML(wood.text)
all_list=word.xpath('//div[@class="table-responsive"]/table[@class="center_table movie_box_office_stats_table table table-bordered table-condensed"]//tr')
for li in all_list:
wa=li.xpath('./td[2]/text()')
title=li.xpath('./td[3]/a/text()')
year=li.xpath('./td[last()-1]/text()')
if wa !=[]:
text=wa[0]+'|'+title[0]+'|'+year[0]
print(text)
with open('wood.txt','a+',encoding='utf-8') as f:
f.write(text+'\n')
Loading…
Cancel
Save