Ch33syNai1a0 2022-12-09 10:39 采纳率: 100%
浏览 39
已结题

求大佬帮忙修改下脚本

为什么运行结果是这样的 不输出到txt里,希望大佬可以帮忙修改一下


# -- coding:UTF-8 --
import re, time
import requests
from fake_useragent import UserAgent
from tqdm import tqdm
import os


# ip138
def ip138_chaxun(ip, ua):
    ip138_headers = {
        'Host': 'site.ip138.com',
        'User-Agent': ua.random,
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
        'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
        'Accept-Encoding': 'gzip, deflate, br',
        'Referer': 'https://site.ip138.com/'}
    ip138_url = 'https://site.ip138.com/' + str(ip) + '/'
    try:
        ip138_res = requests.get(url=ip138_url, headers=ip138_headers, timeout=2).text
        if '
  • 暂无结果
  • '
    not in ip138_res: result_site = re.findall(r"""""", ip138_res) return result_site except: pass # 爱站 def aizhan_chaxun(ip, ua): aizhan_headers = { 'Host': 'dns.aizhan.com', 'User-Agent': ua.random, 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2', 'Accept-Encoding': 'gzip, deflate, br', 'Referer': 'https://dns.aizhan.com/'} aizhan_url = 'https://dns.aizhan.com/' + str(ip) + '/' try: aizhan_r = requests.get(url=aizhan_url, headers=aizhan_headers, timeout=2).text aizhan_nums = re.findall(r'''(.*?)''', aizhan_r) if int(aizhan_nums[0]) > 0: aizhan_domains = re.findall(r'''rel="nofollow" target="_blank">(.*?)''', aizhan_r) return aizhan_domains except: pass def catch_result(i): ua_header = UserAgent() i = i.strip() try: ip = i.split(':')[1].split('//')[1] ip138_result = ip138_chaxun(ip, ua_header) aizhan_result = aizhan_chaxun(ip, ua_header) time.sleep(1) if ((ip138_result != None and ip138_result != []) or aizhan_result != None): with open("IP反查结果列表.txt", 'a') as f: result = "[url]:" + i + " " + "[ip138]:" + str(ip138_result) + " [aizhan]:" + str(aizhan_result) print(result) f.write(result + "\n") else: with open("反查失败.txt", 'a') as f: f.write(i + "\n") except: pass if __name__ == '__main__': url_list = open("目标.txt", 'r').readlines() url_len = len(open("目标.txt", 'r').readlines()) # 每次启动时清空两个txt文件 if os.path.exists("反查失败.txt"): f = open("反查失败.txt", 'w') f.truncate() if os.path.exists("IP反查结果列表.txt"): f = open("IP反查结果列表.txt", 'w') f.truncate() for i in tqdm(url_list): catch_result(i)

    img

    • 写回答

    1条回答 默认 最新

    • 於黾 2022-12-09 10:48
      关注

      f.truncate()是要干什么,你要调用f.write写入你的的数据呀,你的数据都没有使用

      本回答被题主选为最佳回答 , 对您是否有帮助呢?
      评论

    报告相同问题?

    问题事件

    • 已结题 (查看结题原因) 2月16日
    • 已采纳回答 2月16日
    • 创建了问题 12月9日

    悬赏问题

    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序
    • ¥15 多址通信方式的抗噪声性能和系统容量对比
    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作