WatermelonPy 2022-04-06 23:40 采纳率: 100%
浏览 97
已结题

Python 的re为什么匹配不到?正则表达式没错呀

import requests
import re


domain = "https://dy.dytt8.net/index2.htm"
resp = requests.get(domain, verify=False)
resp.encoding = "gb2312"

obj1 = re.compile(r"最新影片推荐.*?<ul>(?P<cont>.*?)</ul>", re.S)
obj2 = re.compile(r"<a href='(?P<href>.*?)'", re.S)
obj3 = re.compile(r'◎片  名(?P<name>.*?)<br />.*?'
                  r'<a target="_blank" href="(?P<download>.*?)">', re.S)

result1 = obj1.finditer(resp.text)
child_href_list = []

for it in result1:
    ul = it.group('ul')

    # 提取子页面链接:
    result2 = obj2.finditer(ul)
    for itt in result2:
        # 拼接子页面的url地址:  域名 + 子页面地址
        child_href = domain + itt.group('href')
        child_href1 = child_href.replace("/index2.htm", "")
        child_href_list.append(child_href1) # 把子页面链接保存起来

for href in child_href_list:
    child_resp = requests.get(href, verify=False)
    child_resp.encoding = 'gb2312'
    result3 = obj3.search(child_resp.text)
    print(result3.group("movie"))
    print(result3.group("download"))

输出为

C:\Users\pc\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/pc/AppData/Roaming/JetBrains/PyCharmCE2021.3/scratches/scratch_13.py
C:\Users\pc\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'dy.dytt8.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
C:\Users\pc\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'dy.dytt8.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
 �C���槭骏�ンダム  �W光のハサウェイ
magnet:?xt=urn:btih:d022c54fb3bd54a9526d5f137fb5c03c2f4c5cae&amp;dn=%e9%98%b3%e5%85%89%e7%94%b5%e5%bd%b1www.ygdy8.com.%e6%9c%ba%e5%8a%a8%e6%88%98%e5%a3%ab%e9%ab%98%e8%be%be%e9%97%aa%e5%85%89%e7%9a%84%e5%93%88%e8%90%a8%e7%bb%b4.2021.BD.1080P.%e6%97%a5%e8%af%ad%e4%b8%ad%e5%ad%97.mkv&amp;tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce&amp;tr=udp%3a%2f%2fexodus.desync.com%3a6969%2fannounce
C:\Users\pc\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'dy.dytt8.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
 The  Alpinist
magnet:?xt=urn:btih:13d1e2e985f47583670461b76f2133fd7dcf1107&amp;dn=%e9%98%b3%e5%85%89%e7%94%b5%e5%bd%b1www.ygdy8.com.%e7%99%bb%e5%b1%b1%e5%ae%b6.2021.BD.1080P.%e4%b8%ad%e8%8b%b1%e5%8f%8c%e5%ad%97.mkv&amp;tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce&amp;tr=udp%3a%2f%2fexodus.desync.com%3a6969%2fannounce
C:\Users\pc\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'dy.dytt8.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
 Spider-Man:  No Way Home/Spider-Man 3/Spider-Man: Home Slice/Spider-Man:  Home-Wrecker/Spider-Man: Phone  Home
magnet:?xt=urn:btih:9c6468e3eb844ff602331fa914b0a6993c184874&amp;dn=%e9%98%b3%e5%85%89%e7%94%b5%e5%bd%b1www.ygdy8.com.%e8%9c%98%e8%9b%9b%e4%be%a0%ef%bc%9a%e8%8b%b1%e9%9b%84%e6%97%a0%e5%bd%92.2021.BD.1080P.%e4%b8%ad%e8%8b%b1%e5%8f%8c%e5%ad%97.mkv&amp;tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce&amp;tr=udp%3a%2f%2fexodus.desync.com%3a6969%2fannounce
C:\Users\pc\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'dy.dytt8.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
 Turning  Red
magnet:?xt=urn:btih:4bf685d1d0fa984df5b49f48c4816c07ae4d0457&amp;dn=%e9%98%b3%e5%85%89%e7%94%b5%e5%bd%b1www.ygdy8.com.%e9%9d%92%e6%98%a5%e5%8f%98%e5%bd%a2%e8%ae%b0.2022.BD.1080P.%e4%b8%ad%e8%8b%b1%e5%8f%8c%e5%ad%97.mkv&amp;tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce&amp;tr=udp%3a%2f%2fexodus.desync.com%3a6969%2fannounce
C:\Users\pc\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'dy.dytt8.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
 Petite  maman / Lille mamma
magnet:?xt=urn:btih:153331d979eb402d46960be3944d02f93f170c20&amp;dn=%e9%98%b3%e5%85%89%e7%94%b5%e5%bd%b1www.ygdy8.com.%e5%b0%8f%e5%a6%88%e5%a6%88.2021.BD.1080P.%e4%b8%ad%e8%8b%b1%e5%8f%8c%e5%ad%97.mkv&amp;tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce&amp;tr=udp%3a%2f%2fexodus.desync.com%3a6969%2fannounce
C:\Users\pc\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'dy.dytt8.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
 West  Side Story
magnet:?xt=urn:btih:b0ab691d2be3126e77d93e72e0ee495ea0378740&amp;dn=%e9%98%b3%e5%85%89%e7%94%b5%e5%bd%b1www.ygdy8.com.%e8%a5%bf%e5%8c%ba%e6%95%85%e4%ba%8b.2021.BD.1080P.%e4%b8%ad%e8%8b%b1%e5%8f%8c%e5%ad%97.mkv&amp;tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce&amp;tr=udp%3a%2f%2fexodus.desync.com%3a6969%2fannounce
C:\Users\pc\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'dy.dytt8.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
 Madres  paralelas / Parallel  Mothers
magnet:?xt=urn:btih:b4bf3f0114059ff049da5958bedc55a65934530d&amp;dn=%e9%98%b3%e5%85%89%e7%94%b5%e5%bd%b1www.ygdy8.com.%e5%b9%b3%e8%a1%8c%e6%af%8d%e4%ba%b2.2021.BD.1080P.%e8%a5%bf%e7%8f%ad%e7%89%99%e8%af%ad%e4%b8%ad%e5%ad%97.mkv&amp;tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce&amp;tr=udp%3a%2f%2fexodus.desync.com%3a6969%2fannounce
C:\Users\pc\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'dy.dytt8.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
 Found
magnet:?xt=urn:btih:e2f20c76bfa11d46f81a6d6b04b283c263aecca0&amp;dn=%e9%98%b3%e5%85%89%e7%94%b5%e5%bd%b1www.ygdy8.com.%e6%89%be%e5%af%bb.2021.BD.1080P.%e4%b8%ad%e8%8b%b1%e5%8f%8c%e5%ad%97.mkv&amp;tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce&amp;tr=udp%3a%2f%2fexodus.desync.com%3a6969%2fannounce
C:\Users\pc\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'dy.dytt8.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
 Le  Sommet des Dieux / The Summit of the  Gods
magnet:?xt=urn:btih:fa06021716929e4c5de250835e7328f747b3fe67&amp;dn=%e9%98%b3%e5%85%89%e7%94%b5%e5%bd%b1www.ygdy8.com.%e7%a5%9e%e4%b9%8b%e5%b1%b1%e5%b2%ad.2021.BD.1080P.%e6%b3%95%e8%af%ad%e4%b8%ad%e5%ad%97.mkv&amp;tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce&amp;tr=udp%3a%2f%2fexodus.desync.com%3a6969%2fannounce
C:\Users\pc\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'dy.dytt8.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
 Scream/Scream  5
magnet:?xt=urn:btih:3568c07aa97af473fd547eec7649f94239150939&amp;dn=%e9%98%b3%e5%85%89%e7%94%b5%e5%bd%b1www.ygdy8.com.%e6%83%8a%e5%a3%b0%e5%b0%96%e5%8f%ab5.2022.BD.1080P.%e4%b8%ad%e8%8b%b1%e5%8f%8c%e5%ad%97.mkv&amp;tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce&amp;tr=udp%3a%2f%2fexodus.desync.com%3a6969%2fannounce
C:\Users\pc\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'dy.dytt8.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
 映画クレヨンしんちゃん  �iメキ!花の天カス学�@
magnet:?xt=urn:btih:acd85204ef63f4c09bdf42f583566af763e9c9c8&amp;dn=%e9%98%b3%e5%85%89%e7%94%b5%e5%bd%b1www.ygdy8.com.%e8%9c%a1%e7%ac%94%e5%b0%8f%e6%96%b0%ef%bc%9a%e8%b0%9c%e5%9b%a2.2021.BD.1080P.%e5%9b%bd%e7%b2%a4%e6%97%a5%e4%b8%89%e8%af%ad%e4%b8%ad%e5%ad%97.mkv&amp;tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce&amp;tr=udp%3a%2f%2fexodus.desync.com%3a6969%2fannounce
C:\Users\pc\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'dy.dytt8.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
 King  Richard
magnet:?xt=urn:btih:72641444ec15aabadf1aa32d28a601e66ec66b27&amp;dn=%e9%98%b3%e5%85%89%e7%94%b5%e5%bd%b1www.ygdy8.com.%e5%9b%bd%e7%8e%8b%e7%90%86%e6%9f%a5%e5%be%b7.2021.BD.1080P.%e4%b8%ad%e8%8b%b1%e5%8f%8c%e5%ad%97.mkv&amp;tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce&amp;tr=udp%3a%2f%2fexodus.desync.com%3a6969%2fannounce
C:\Users\pc\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'dy.dytt8.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
 American  Underdog: The Kurt Warner Story/American  Underdog
magnet:?xt=urn:btih:db673fd0dd7ecad002183657112732e38727df77&amp;dn=%e9%98%b3%e5%85%89%e7%94%b5%e5%bd%b1www.ygdy8.com.%e7%be%8e%e5%9b%bd%e8%8d%89%e6%a0%b9%ef%bc%9a%e5%ba%93%e5%b0%94%e7%89%b9%c2%b7%e5%8d%8e%e7%ba%b3%e7%9a%84%e6%95%85%e4%ba%8b.2021.BD.1080P.%e4%b8%ad%e8%8b%b1%e5%8f%8c%e5%ad%97.mkv&amp;tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce&amp;tr=udp%3a%2f%2fexodus.desync.com%3a6969%2fannounce
C:\Users\pc\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'dy.dytt8.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
Traceback (most recent call last):
  File "C:\Users\pc\AppData\Roaming\JetBrains\PyCharmCE2021.3\scratches\scratch_13.py", line 31, in <module>
    print(result3.group("movie"))
AttributeError: 'NoneType' object has no attribute 'group'

Process finished with exit code 1

匹配的内容为

img

  • 写回答

1条回答 默认 最新

    报告相同问题?

    相关推荐 更多相似问题

    问题事件

    • 系统已结题 4月16日
    • 已采纳回答 4月8日
    • 修改了问题 4月6日
    • 创建了问题 4月6日

    悬赏问题

    • ¥20 python 爬虫 token 加密方式
    • ¥20 IAR环境报错reading CPU status failed
    • ¥15 数组问题,刚学C语言
    • ¥20 Python如何读取指定播放设备的音频帧?
    • ¥15 用dnspy修改游戏数据报错
    • ¥15 关于unity打包成webgl后页面上不显示服务端接收到的数据的问题
    • ¥16 (大一)有偿 想学会 excel数据处理和分析🥹
    • ¥15 matlab导入工具箱提示:此类型的变量不支持使用点进行索引错误
    • ¥20 用Java实现双向链表
    • ¥15 数据库系统,可以来看看