使用newspaper3k爬取新闻网页的正常写法
article = Article(url, language="en")
article.download()
article.parse()
但是在爬取某些网站时会遇到SSLError的报错(代理问题)
解决方案是:
首先你需要有一个proxy IP,根据需要修改即可
proxies = {
"http": "http://127.0.0.1:7890",
"https": "http://127.0.0.1:7890",
}
将article.download()改用request方法,并带上上一步的proxies
article = Article(url, language="en")
html = request.get(url, verify=False, proxies=proxies)
article.set_html(html.text)
article.parse()
然后就可以顺利爬取到你想要的新闻网页了