Python40行代码爬取电影天堂的电影下载连接
比较基础的爬虫
import re
import requests
import csv
o1 = re.compile(r'2021新片精品.*?<ul>(?P<ul>.*?)</ul>', re.S)
o2 = re.compile(r"href='(?P<href>.*?)' title", re.S)
o3 = re.compile(r'◎片 名 (?P<name>.*?)<br />.*? <td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><a href="'
r'(?P<downurl>.*?)">magnet:?', re.S)
url = 'https://dytt89.com/'
r = requests.get(url, verify=False)
r.encoding = r.apparent_encoding
c = r.text
# print(c)
i1 = o1.finditer(c)
lst = []
for i in i1:
c1 = i.group('ul')
# print(c1)
i2 = o2.finditer(c1)
for j in i2:
lst.append(j.group('href'))
# print(lst)
f = open("data1.csv", mode="w", encoding="utf-8", newline='')
cw = csv.writer(f)
cnt = 0
for i in lst:
sub_url = url + i.strip('/')
sub_r = requests.get(sub_url, verify=False)
sub_r.encoding = sub_r.apparent_encoding
sub_c = sub_r.text
i3 = o3.search(sub_c)
dic = i3.groupdict()
cw.writerow(dic.values())
cnt += 1
if cnt >= 10:
break
f.close()
r.close()
data1.csv
Mortal Kombat,magnet:?xt=urn:btih:f9f2f48e0e90b5567d2a7c077a10d4ddc8518706&dn=[电影天堂www.dytt89.com]真人快打-2021_HD中英双字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce
The Courier,magnet:?xt=urn:btih:31d68ead23d6620a0240b8e5a3d2ea09adc9045b&dn=[电影天堂www.dytt89.com]信使-2020_BD中英双字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce
서복,magnet:?xt=urn:btih:d5c8f3745d2274d3b874bfec3ad177c77d1348d3&dn=[电影天堂www.dytt89.com]徐福-2021_BD韩语中字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce
Nobody,magnet:?xt=urn:btih:ef6006794b90b446ce8a55957b2aa26c76388642&dn=[电影天堂www.dytt89.com]小人物-2021_BD中英双字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce
��魂,magnet:?xt=urn:btih:9d3ae0c83e58a260e45fb525f9341da00848c11d&dn=[电影天堂www.dytt89.com]缉魂-2021_HD国语中字无删减版.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce
人潮汹涌,magnet:?xt=urn:btih:6835a47849c56cf9a431c1cbb903eece18735f33&dn=[电影天堂www.dytt89.com]人潮汹涌-2021_HD国语中字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce
刺杀小说家,magnet:?xt=urn:btih:f269992eb6cf6ad253c75a42739f44d1b02432b4&dn=[电影天堂www.dytt89.com]刺杀小说家-2021_HD国语中字V2.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce
浅田家!,magnet:?xt=urn:btih:d2cbcd17feeb04d4f5834e211f5f65c4816f28ce&dn=[电影天堂www.dytt89.com]浅田家!-2020_BD日语中字.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce
Raya and The Last Dragon,magnet:?xt=urn:btih:d836e530d856d41bc4410634bcde289a265ccbf2&dn=[电影天堂www.dytt89.com]寻龙传说-2021_BD中英双字V2.mp4&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce
新神榜:哪吒重生,magnet:?xt=urn:btih:89847e3934f8a5ccdff2cd0e74bb1c6d17a24641&dn=[电影天堂www.dytt89.com]新神榜:哪吒重生-2021_HD国粤双语中字.mkv&tr=http://t.t789.me:2710/announce&tr=http://t.t789.co:2710/announce&tr=http://t.t789.vip:2710/announce