Python使用urllib读取google搜索结果

标签 python urllib

我有以下代码:

def downloadData(queryString):
    with urllib.request.urlopen(queryString) as url:
        encoding = url.headers.get_content_charset()
        result = url.read().decode(encoding)
    return result

但是对于返回 https 文档的 google,我收到错误:

urllib.error.HTTPError: HTTP Error 403: Forbidden

这是查询字符串:

https://www.google.com/search?q=Dow+Jones+Industrial+Average+Quote+with+volume

我需要如何更改它才能处理 https?谢谢!

最佳答案

关于Python使用urllib读取google搜索结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21680558/

相关文章:

python - 捕获 SysLogHandler 的输出

python - 创建按列分组的箱线图

python - “urllib.error.HTTPError: HTTP Error 404: Not Found” Python

python-3.x - 在 Python 3 中使用 urllib 重定向 url

python - 在python中使用urllib时感应受密码保护的网站

python - 使用 **kwargs 在 factory boy test 中调用函数

python - 输入时间限制/倒计时

python - ssl.wrap_socket 在go中的实现

python - 用 python 抓取图像但找不到图像

Python urljoin 没有正确地将相对和绝对 url 连接在一起