爬取电影天堂
返回电影名+磁力链接
import re
import requests
url_1 = 'https://www.dytt89.com/' # 电影天堂
re1 = re.compile(r'2021新片精品.*?<ul>(?P<ul>.*?)<ul>', re.S) # 拿页面板块
re2 = re.compile(r"<a href='(?P<href>.*?)'", re.S) # 拿跳转链接
re3 = re.compile(r"◎片 名 (?P<name>.*?)<br />",re.S) # 拿电影片名
re4 = re.compile(r"◎片 名 (?P<name>.*?)<br />.*?magnet:\?xt=(?P<down>.*?)=",re.S) # 片名+磁力
domain = requests.get(url_1); domain.encoding = 'gbk'
tmp1 = re.finditer(re1, domain.text)
for i in tmp1:
# print(i.group('ul'))
tmp2 = re.finditer(re2, i.group('ul'))
for j in tmp2 :
href = url_1 + j.group('href').strip("/")
href_movie = requests.get(href)
href_movie.encoding = 'gbk'
res = re.findall(re4,href_movie.text)
magnet = "magnet:?xt="+ res[0][1]
a = res[0][0]; b = magnet
print("{:<66s}\t\t\t{:>50}".format(a, b))
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/86c74666225d8fa4d2b9b09f06824011.png)