如何在抓取请求时绕过 Google Recaptcha

k m*_*ish 5 python beautifulsoup web-scraping python-requests

请求 URL 的 Python 代码:

agent = {"User-Agent":'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'} #using agent to solve the blocking issue
response = requests.get('https://www.naukri.com/jobs-in-andhra-pradesh', headers=agent)
#making the request to the link
Run Code Online (Sandbox Code Playgroud)

打印 html 时的输出:

<!DOCTYPE html>

<html>
  <head>
    <title>Naukri reCAPTCHA</title> #the title in the actual title of the URL that I am requested for
    <meta name="robots" content="noindex, nofollow">
        <link rel="stylesheet" href="https://static.naukimg.com/s/4/101/c/common_v62.min.css" />      
        <script src="https://www.google.com/recaptcha/api.js" async defer></script>   
    </head>
</html>
Run Code Online (Sandbox Code Playgroud)

Jos*_*hua 13

使用Google Cache具有沿referer(在头)将帮助你绕过验证码。
注意事项:

  • 不要发送超过 2 个请求/秒。你可能会被屏蔽。
  • 您收到的结果是一个缓存。如果您试图抓取实时数据,这将无效。
    例子:
header = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36" ,
    'referer':'https://www.google.com/'
}

r = requests.get("http://webcache.googleusercontent.com/search?q=cache:www.naukri.com/jobs-in-andhra-pradesh",headers=header)
Run Code Online (Sandbox Code Playgroud)

这给出:

>>> r.content
[Squeezed 2554 lines]
Run Code Online (Sandbox Code Playgroud)