对了好几遍还是找不到哪里出了问题


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'
'''

额,要re的compile的东西遍历后才有group,其他的都没有,你的这里只有result1遍历后的it才有group,你的child_href_list是列表,没有group的哦
有用的话点一下采纳

是空的,你的正则可能写错了,你检查一下,不要抄视频的,因为网址的源代码可能会有一点变化
img
img

有用的话点一下采纳