基于Python爬取fofa网页端数据过程解析
FOFA-网络空间安全搜索引擎是网络空间资产检索系统(FOFA)是世界上数据覆盖更完整的IT设备搜索引擎,拥有全球联网IT设备更全的DNA信息。探索全球互联网的资产信息,进行资产及漏洞影响范围分析、应用分布统计、应用流行度态势感知等。
安装环境:
pip install requests
pip install lxml
pip install fire
使用命令:
python fofa.py -s=title="你的关键字" -o="结果输出文件" -c="你的cookie"
代码如下:
import requests,time,base64,fire from lxml import etree def fofasc(s,o,c): try: sbase64 = (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?q="+s+"&qbase64="+sbase64+"&full=true&page="+str(i) r = requests.get(url, headers=headers, cookies=cookies) soup = etree.HTML(r.text) result = soup.xpath('//*[@id="ajax_content"]/div/div/div/a/text()') print(result) if result != []: for rs in result: with open(o,mode="a+") as f: f.write(rs+"\n") else: print("已经获取不到任何数据,爬取完毕!") break time.sleep(2) except KeyboardInterrupt: print('用户退出') if __name__ == '__main__': fire.Fire(fofasc)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
Python数据可视化编程通过Matplotlib创建散点图代码示例
这篇文章主要介绍了Python数据可视化编程通过Matplotlib创建散点图实例,具有一定借鉴价值,需要的朋友可以参考下。2017-12-12解决Python pandas plot输出图形中显示中文乱码问题
今天小编就为大家分享一篇解决Python pandas plot输出图形中显示中文乱码问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2018-12-12Python 继承,重写,super()调用父类方法操作示例
这篇文章主要介绍了Python 继承,重写,super()调用父类方法,结合完整实例形式详细分析了Python面向对象程序设计中子类继承与重写父类方法的相关操作技巧,需要的朋友可以参考下2019-09-09
最新评论