zoukankan      html  css  js  c++  java
  • FOFA网页爬取最新 批量版本《转自aptkekeo》

    转自

    aptkekeo博客

    安装环境:

    pip install requests
    pip install lxml
    pip install fire
    

    使用命令:

    python fofa.py -s="爬取的txt" -o="结果输出文件" -c="你的cookie"
    注意:-o输入文件名即可,程序自动加入.txt后缀

    FOFA网页爬取源代码:

    import requests,time,base64,fire
    from lxml import etree
    
    def fofasc(s,o,c):
        try:
            qbase64 = (base64.b64encode(s.encode('utf-8'))).decode('utf-8')
            cookies = {
                "_fofapro_ars_session": c
            }
    
            headers = {
                'User-Agent': 'Mozilla/5.0 (Linux; Android 7.1.2; PCRT00 Build/N2G48H; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.158 Safari/537.36 fanwe_app_sdk sdk_type/android sdk_version_name/4.0.1 sdk_version/2020042901 screen_width/720 screen_height/1280',
            }
            for i in range(1,1000):
                url = "https://www.fofa.so/result?qbase64="+qbase64+"&full=true&page="+str(i)+'&per_page=20'
                r = requests.get(url, headers=headers, cookies=cookies)
                soup = etree.HTML(r.text)
                result = soup.xpath('//*[@id="ajax_content"]/div/div[1]/div[1]/a[@target="_blank"]/@href')
                if result != []:
                    for rs in result:
                        print(rs)
                        with open(o,mode="a+") as f:
                            f.write(rs+"
    ")
                else:
                    print("已经获取不到任何数据,爬取完毕!")
                    break
                print("爬取完成:第%s页"%i)
                time.sleep(5)
        except KeyboardInterrupt:
            print('用户退出')
    
    def batch(s,c,o):
        with open(s,"r+",encoding="utf-8") as f:
            name = 1
            for i in f:
                i = i.strip("
    ")
                fofasc(s=i, o=(o+str(name) + ".txt"), c=c)
                name += 1
    
    if __name__ == '__main__':
        fire.Fire(batch)
    
  • 相关阅读:
    [前端开发]Vue组件化的思想
    [前端开发]数组中哪些方法是响应式的
    冒泡排序和选择排序
    css定位属性的运用
    JS拖拽效果的原理及实现
    Js函数的形参和实参详解
    Js中的For循环详解
    什么是盒模型?
    关于使用JS去除URL中的指定参数问题,js 对url进行某个参数的删除,并返回url
    听力的尝试
  • 原文地址:https://www.cnblogs.com/lovesickness/p/13322799.html
Copyright © 2011-2022 走看看