不能一事无成,这么久了学python还是吊着,要落地,落在博客园好了,好像公司也只能上博客园了

昨天看了一篇用正则爬电影天堂的视频,直接拿来用,爬磁力吧,爬好玩的

 1 #导入模块
 2 import requests
 3 import re
 4 
 5 #用一个变量接受输入
 6 input_name = input("输入关键字搜索:")
 7 
 8 for n in range(1,2): #n是页码 看情况,想多搜就放大点
 9     # 网址 用+ +进行拼接,还很好用
10     a_url = 'https://www.ciliba.org/s/'+input_name+'_rel_'+str(n)+'.html'  
11     html_1 = requests.get(a_url)
12     html_1.encoding = 'utf-8' #转码
13     print(html_1.status_code) #返回码为200则说明能爬
14     detail_list = re.findall('<div class="item-title"><h3><a href="(.*?)" target="_blank',html_1.text)
15     #print(detail_list)
16     for m in detail_list:
17         html_2 = requests.get(m)
18         html_2.encoding = 'utf-8'
19         ftp = re.findall('资源下载:<a href="(.*?)" class="download" >磁力链接</a>',html_2.text)
20         #print(ftp)
21         with open('C:\\Users\\wyx\\Desktop\\'+input_name+'的磁力链.txt','a',encoding='utf-8') as ff:
22                  ff.write(ftp[0]+'\n')
23 print("the search is done")

 

最后在桌面上形成相关关键字的文件,我试了苍老师,可以的

很入门,努力中