首页 > 解决方案 > 请求在本地笔记本上工作,但在云笔记本上返回 403

问题描述

我在本地 jupyter notebook 上制作了一个 RSS 刮板,它正在工作,但是当我将它放入 Google Colab 时,我的一个 RSS 源出现 403 错误。退货内容如下:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access this resource.</p>
<p>Additionally, a 403 Forbidden
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>

为什么这只在我的云笔记本上?如何解决这个问题?

对于那些想要复制的人:

import requests
from bs4 import BeautifulSoup

rss = 'http://www.investimentosenoticias.com.br/noticias?format=feed'

r = requests.get(rss)
soup = BeautifulSoup(r.content, features='xml')
print(soup)

标签: xmlweb-scrapinggetrssgoogle-colaboratory

解决方案


推荐阅读