爬取Google的心酸之路

admin 2023年5月18日09:36:38评论21 views字数 2517阅读8分23秒阅读模式


零基础黑客教程,黑客圈新闻,安全面试经验

尽在 # 掌控安全EDU #


0x00前言


早在前段时间就尝试写过爬Google的了。当时由于解决不了验证码就删了,当然这次也没解决。验证码不能绕过,只能避免,减少遇见

0x001过程


爬虫我追求,快、稳。但是由于Google这恶心的验证码机制,导致我不得不放弃这个想法。转而花费大量时间来解决频频碰到验证码的问题

写法只有请求,不换user-agent头的,加上多进程或多线程调用。一次就封IP了

import requests
rqt=requests.get(url='https://www.google.com/search?q=xxx&start=1',headers={'user-agent':'Google Splider'},timeout=3)


后面参考了几篇文章和一个项目:

对于 Python 抓取 Google 搜索结果的一些了解:

https://juejin.im/post/5c2c6bbee51d450d5a01d70a

Google_search

https://github.com/MarioVilas/googlesearch

看了这两个操作之后,发现都是用了同一操作

随机User-Agent头
随机使用Google的搜索子域



爬取Google的心酸之路

收集的User-agent头

爬取Google的心酸之路

实现这两种随机很容易,只需全部放入两个数组。使用random.choice()随机抽取即可

def read():
    dk=open('user_agents.txt','r',encoding='utf-8')
    for r in dk.readlines():
        data="".join(r.split('n'))
        yield data

def reads():
    dk=open('domain.txt','r',encoding='utf-8')
    for r in dk.readlines():
        data="".join(r.split('n'))
        yield data


def fenpei(proxy,search,page,sleep):
    user_agents=[]
    google_searchs=[]
    for ua in read():
        user_agents.append(ua)


    for domain in reads():
        google_searchs.append(domain)


虽然实现随机了,但是还是很脆弱。还是经不起Google那个狗贼般的验证码的摧残,在给其加上一个延时


import random
import requests
import time

def read():
    dk=open('user_agents.txt','r',encoding='utf-8')
    for r in dk.readlines():
        data="".join(r.split('n'))
        yield data

def reads():
    dk=open('domain.txt','r',encoding='utf-8')
    for r in dk.readlines():
        data="".join(r.split('n'))
        yield data


def fenpei(proxy,search,page,sleep):
    user_agents=[]
    google_searchs=[]
    for ua in read():
        user_agents.append(ua)


    for domain in reads():
        google_searchs.append(domain)

    time.sleep(int(sleep))
    proxy={'http':'http://{}'.format(proxy),'https':'https://{}'.format(proxy)}
    domains=random.choice(google_searchs)
    u_s={'user-agent':random.choice(user_agents),'Content-type':"text/html;charset=utf-8"}
    url='https://{}/search?hl=Chinese&q={}&btnG=Search&gbv=10&start={}'.format(domains,search,page)
    requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)
    rqt=requests.get(url=url,headers=u_s,allow_redirects=False,verify=False,proxies=proxy,timeout=30)
    return rqt.content


0x002完整代码


Github仓库地址:https://github.com/422926799/note/tree/master/%E8%87%AA%E5%B7%B1%E5%86%99%E7%9A%84%E5%B7%A5%E5%85%B7/google%E6%8A%93%E5%8F%96

成功抓取如下

爬取Google的心酸之路

遇见验证码

爬取Google的心酸之路


支持IP代理池

爬取Google的心酸之路


成功抓取如下图


爬取Google的心酸之路




黑客教程~ 课件 靶场 ~ 限!时!免费!送!

长按识别二维码,即可限时免费报名课程。


爬取Google的心酸之路



以就业为导向的专业付费课

   直播+录播+一周七天辅导员轮岗教学  


 扫描下方二维码 立刻咨询助教老师!

 加好友请备注暗号:GG,还有优惠!



爬取Google的心酸之路




                                   点击在看~好文大家给一起看!👇

原文始发于微信公众号(掌控安全EDU):爬取Google的心酸之路

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年5月18日09:36:38
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   爬取Google的心酸之路http://cn-sec.com/archives/946826.html

发表评论

匿名网友 填写信息