Python中的Google搜索错误:503服务不可用 [英] Error with Google search in Python: 503 Service Unavailable

查看:121
本文介绍了Python中的Google搜索错误:503服务不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在python控制台中进行操作时:

When I try to do in a python console:

from google import search
urls = search("site:facebook.com inurl:login", stop=20)
for url in urls:
    print(url)

为了搜索登录页面,我得到一个错误:

In order to search login pages, I obtain an error:

urllib.error.HTTPError: HTTP Error 503: Service Unavailable

但是,如果我尝试在Google中手动搜索它,那么它会起作用吗,谷歌会阻止我的查询吗?

However, if I try to search it in Google manually it works, might google be blocking my query?

推荐答案

Google确实尝试阻止意外"查询通过.在正常的浏览器用户界面中,它将提供验证码.它将考虑流量模式(使用智能"查询的搜索速度太快,已知垃圾邮件发送者使用的IP阻止)以及客户端的行为.

Google does try to prevent "unexpected" queries from going through. In the normal browser UI it would serve a captcha. It will take into account the traffic pattern (too rapid searches with "smart" queries, IP block known to be used by spammers) and the behavior of the client.

您可以通过捕获错误来检查错误的详细信息.

You can examine the error's detail by catching it.

try:
    urls = search("site:facebook.com inurl:login", stop=20)
except urllib.error.HTTPError as httperr:
    print(httperr.headers)  # Dump the headers to see if there's more information
    print(httperr.read())   # You can even read this error object just like a normal response file

这篇关于Python中的Google搜索错误:503服务不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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