[Handbook]一键某察者新闻

98 篇文章 1 订阅
8 篇文章 0 订阅

Python Code

"""
@author: MR.N
@created: 2022/9/24 Sat. 23:45
@file: se_guancha_1
@version: 1.0
"""

from httpkit import *
from scrapy import Selector
# import re
from filtertags import *
import time
import os


def test(url='https://www.guancha.cn'):
    remote_task = RemoteTask(url=url)
    ret = []
    code = get_res_objects2(remote_task=remote_task, ret=ret, dtype=0)
    if code != 'success':
        return None
    content = ret[0]
    sel = Selector(text=content)
    # 新闻标题包含于具有特定特征码的h4标签
    links = sel.xpath('//ul/li/h4').getall()
    sources = []
    for link in links:
        # 包含新闻标题的A标签具有title属性
        if len(filter_html_tags(link)) > 4:
            sources.append(filter_html_tags(link).replace('  ', '').replace('\n', ''))
    if len(sources) < 1:
        print('err', content)
    return sources


if __name__ == '__main__':
    items = test()
    # print('\n\n'.join(items))
    for item in items:
        print('\n\n\t' + item)
        time.sleep(.6)

Example

result

Error

URLError / SSLEOFError

Description

“urllib.error.URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:1131)>” or “ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1131)”

Cause(s)

  1. 不稳定的网络状态
    2)HTTPS(SSL)握手失败拒绝服务
    3)urllib3不同版本的SSL配置错误
user@pc:~$ pip install urllib3==1.25.11
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值