代码
import requests
import re
domain = 'https://dytt89.com/'
resp = requests.get(domain, verify=False) # verify=False 去掉安全验证
resp.encoding = 'gb2312' # 指定字符集,跟网页内的一致
# print(resp.text)
# 拿到li
obj = re.compile(r'2022必看热片.*?<ul>(?P<ul>.*?)</ul>', re.S)
obj1 = re.compile(r"<a href='(?P<href>.*?)'", re.S)
obj2 = re.compile(r'◎片 名(?P<movie>.*?)<br />.*?<td style="WORD-WRAP: break-word" bgcolor="#fdfddf">'
r'<a href="(?P<download>.*?)">', re.S)
ret = obj.finditer(resp.text)
child_list = []
for it in ret:
ul = it.group('ul')
ret2 = obj1.finditer(ul)
for it2 in ret2:
child_href = domain + it2.group('href').strip('/')
child_list.append(child_href)
# 请求子页面
for href in child_list:
child_resp = requests.get(href, verify=False)
child_resp.encoding = 'gb2312'
# print(child_resp.text)
ret3 = obj2.search(child_resp.text)
print('电影名称:{0} - 下载地址:{1}'.format(ret3.group('movie'), ret3.group('download')))
resp.close()