为什么Google搜索返回HTTP错误403? [英] Why does Google Search return HTTP Error 403?

查看:460
本文介绍了为什么Google搜索返回HTTP错误403?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下Python代码:

Consider the following Python code:


 30    url = "http://www.google.com/search?hl=en&safe=off&q=Monkey"
 31    url_object = urllib.request.urlopen(url);
 32    print(url_object.read());

运行此命令时,将引发异常:

When this is run, an Exception is thrown:

File "/usr/local/lib/python3.0/urllib/request.py", line 485, in http_error_default
   raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

但是,将其放入浏览器后,搜索将按预期返回.这里发生了什么?如何克服这个问题,以便可以通过编程方式搜索Google?

However, when this is put into a browser, the search returns as expected. What's going on here? How can I overcome this so I can search Google programmatically?

有什么想法吗?

推荐答案

如果您想通过编程界面适当"进行Google搜索,请查看

If you want to do Google searches "properly" through a programming interface, take a look at Google APIs. Not only are these the official way of searching Google, they are also not likely to change if Google changes their result page layout.

这篇关于为什么Google搜索返回HTTP错误403?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆