From 553879305deca6dee12340e4f0bbea579c3ea3ff Mon Sep 17 00:00:00 2001 From: hnu202009070122 Date: Mon, 14 Jun 2021 22:41:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=BA=94=E5=85=B3=E7=94=B5=E5=BD=B1?= =?UTF-8?q?=E7=A5=A8=E6=88=BF=E6=95=B0=E6=8D=AE=E7=88=AC=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 新建文本文档 (3).txt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 新建文本文档 (3).txt diff --git a/新建文本文档 (3).txt b/新建文本文档 (3).txt new file mode 100644 index 0000000..30cb21a --- /dev/null +++ b/新建文本文档 (3).txt @@ -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')