吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 967|回复: 5
收起左侧

[求助] 第二次求助,到正则表达式2测试结果都是正常的。

[复制链接]
zqlcpu 发表于 2022-5-29 22:36
[Python] 纯文本查看 复制代码
import requests
import re

domain = "https://www.dytt89.com"
resp = requests.get(domain,verify=False)  #verify=False 去掉安全验证
resp.encoding = "gb2312"

#print(resp.text)

obj1 = re.compile(r'2022新片精品.*?<ul>(?P<ul>.*? )</ul>',re.S)  #正则表达式1
obj2 = re.compile(r"<li><a href='(?P<href>.*?)'",re.S)    #正则表达式2
obj3 = re.compile(r'◎译名(?P<movie>.*?)<br />.*?<td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><a 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").strip("/")
        child_href_list.append(child_href) #把子页面链接保存起来
        #print(itt.group("href"))
    #print(ul)
        
for href in child_href_list:
    child_resp = requests.get(href,verify=False)
    child_resp.enconding = "gb2312"
    #print(child_resp.text)
    result3 = obj3.search(child_resp.text)
    print(result3.group("movie"))
    print(result3.group("download"))
    break  #测试使用
          

免费评分

参与人数 1热心值 +1 收起 理由
dgy + 1 用心讨论,共获提升!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| zqlcpu 发表于 2022-5-29 22:37
本帖最后由 zqlcpu 于 2022-5-29 22:39 编辑

错误提示:如下 Python 3.11.0a7 (main, Apr  5 2022, 21:27:39) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.

================= RESTART: C:\Users\zqlcpu\Desktop\实战5.0(失败).py ================

Warning (from warnings module):
  File "E:\python3.10.4\Lib\site-packages\urllib3\connectionpool.py", line 1043
    warnings.warn(
InsecureRequestWarning: Unverified HTTPS request is being made to host 'www.dytt89.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
Traceback (most recent call last):
  File "E:\python3.10.4\Lib\site-packages\urllib3\connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "E:\python3.10.4\Lib\site-packages\urllib3\util\connection.py", line 72, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "E:\python3.10.4\Lib\socket.py", line 955, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\python3.10.4\Lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "E:\python3.10.4\Lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "E:\python3.10.4\Lib\site-packages\urllib3\connectionpool.py", line 1040, in _validate_conn
    conn.connect()
  File "E:\python3.10.4\Lib\site-packages\urllib3\connection.py", line 358, in connect
    self.sock = conn = self._new_conn()
  File "E:\python3.10.4\Lib\site-packages\urllib3\connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x000001E49AE2FDD0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\python3.10.4\Lib\site-packages\requests\adapters.py", line 440, in send
    resp = conn.urlopen(
  File "E:\python3.10.4\Lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "E:\python3.10.4\Lib\site-packages\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.dytt89.comi', port=443): Max retries exceeded with url: /105613.html (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001E49AE2FDD0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\zqlcpu\Desktop\实战5.0(失败).py", line 29, in <module>
    child_resp = requests.get(href,verify=False)
  File "E:\python3.10.4\Lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "E:\python3.10.4\Lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "E:\python3.10.4\Lib\site-packages\requests\sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "E:\python3.10.4\Lib\site-packages\requests\sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "E:\python3.10.4\Lib\site-packages\requests\adapters.py", line 519, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.dytt89.comi', port=443): Max retries exceeded with url: /105613.html (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001E49AE2FDD0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

三滑稽甲苯 发表于 2022-5-29 23:07
Harold123 发表于 2022-5-29 23:10
你的最后href网址错了,
第23行 child_href = domain + itt.group("href").strip("/")
拼接网址少了个‘‘/’’
https://www.dytt89.comi/105631.html
应该是
https://www.dytt89.com/i/105631.html
tiancaiashuai 发表于 2022-5-30 08:16
这是那个EXCEL用的正则吗
jxji 发表于 2022-5-30 17:44
四楼正解,报错信息很明确了:socket.gaierror: [Errno 11001] getaddrinfo failed

域名拼接错了
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-25 11:25

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表