import requests
import base64
from lxml import etree
import time
search_data='' //要爬取的内容
headers={
# 'cookie':'你的cookie'
}
for yeshu in range(1,6):
url='https://fofa.info/result?page='+str(yeshu)+'&qbase64='
search_data_bs=str(base64.b64encode(search_data.encode("utf-8")),"utf-8")
urls=url+search_data_bs
print(urls)
try:
print('正在提取第'+str(yeshu)+'页')
result=requests.get(urls,headers=headers).content
# print(result.decode('utf-8'))
soup=etree.HTML(result)
ip_data=soup.xpath('//a[@target="_blank"]/@href')
ipdata='\n'.join(ip_data)
print(ip_data)
with open(r'thinkphp5.txt','a+') as f:
f.write(ipdata+'\n')
f.close()
time.sleep(0.5)
except Exception as e:
pass