当前位置: 首页 > 工具软件 > Newspaper > 使用案例 >

newspaper3k遇到SSLError解决方案

戚锦
2023-12-01

使用newspaper3k爬取新闻网页的正常写法

article = Article(url, language="en")
article.download()
article.parse()

但是在爬取某些网站时会遇到SSLError的报错(代理问题)

解决方案是:

  1. 首先你需要有一个proxy IP,根据需要修改即可

proxies = {
    "http": "http://127.0.0.1:7890",
    "https": "http://127.0.0.1:7890",
}
  1. 将article.download()改用request方法,并带上上一步的proxies

article = Article(url, language="en")
html = request.get(url, verify=False, proxies=proxies)
article.set_html(html.text)
article.parse()

然后就可以顺利爬取到你想要的新闻网页了

 类似资料: