我已经四处寻找了一段时间来寻找答案,但不幸的是今天没有运气。
我正在尝试从该网页获取内容并将其保存到变量中。 (Link to the website)
如果您对我的意思感到困惑,请在评论中提出问题,任何帮助都会很棒,因为我个人不确定如何很好地表达这一点。
请不要让我失望,我知道你能做到;)
最佳答案
您需要安装请求。希望您了解 pip
,否则请阅读并安装它。
pip 安装请求
然后在您的代码中:
import requests
url = "http://rivalregions.com/rss/all"
req = requests.get(url)
if req.status_code in [200]:
html = req.text
else:
print 'Could not retrieve: %s, err: %s - status code: %s' % (url, req.text, req.status_code)
html = None
关于python - 如何在Python中将网页数据保存到变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47213315/