import requests
import re
domain='https://www.dytt89.com/'
resp=requests.get(domain)
resp.encoding='gb2312'
obj1=re.compile(r"2021必看热片.*?<ul>(?P<ul>.*?)</ul>",re.S)
obj2=re.compile(r"<a href='(?P<href>.*?)'",re.S)
obj3=re.compile(r'◎片 名(?P<movie>.*?)<br />.*?'
r'<td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><a href="(?P<address>.*?)”>',re.S)
result1=obj1.finditer(resp.text)
child_href_list=[]
for it in result1:
ul=it.group('ul')
#print(ul)
result2 = obj2.finditer(ul)
for it2 in result2:
child_href = domain + it2.group('href').strip('/')
child_href_list.append(child_href)
for href in child_href_list:
resp2 = requests.get(href)
resp2.encoding = 'gb2312'
r3 = obj3.search(resp2.text)
print(r3.group('movie'))
print(r3.group('address'))
结果一直是
Traceback (most recent call last):
File "D:/pachong/第二章/04.py", line 27, in
print(r3.group('movie'))
AttributeError: 'NoneType' object has no attribute 'group'
'''