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 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大