首页 > 其他分享 >批量检测URL中的关键词,并且将不含有关键词的URL输出到txt文件当中

批量检测URL中的关键词,并且将不含有关键词的URL输出到txt文件当中

时间:2023-02-08 16:45:27浏览次数:32  
标签:futures tuple URL 关键词 url import txt

编写代码时遇到的问题

  • 写入txt(一开始忘记了tuple类型需要转换为str)
  • 处理逻辑(一开始并没有将 body与url绑定到一起,所以或返回所有的url)
  • 关闭太早(这点是有点疑惑的,难道不用关闭文本么?加了一个f.close就错了)
  • 匹配时忘记了大小写
import requests
from bs4 import BeautifulSoup
import pandas as pd
from openpyxl import Workbook
import concurrent.futures

# 读取 .txt 文件中的 URL
with open("urls.txt", "r") as file:
    urls = file.read().splitlines()

# 存储 URL 
data = []

def detect_cvss(url):
    try:
        response = requests.get(url)
        soup = BeautifulSoup(response.text, "html.parser")
        body = soup.find("body").text
        tuple=(url,body)
        if "xxxx" not in tuple[1]:
            print(tuple[0])
            return (tuple[0])
    except:
        return None

with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
    futures = [executor.submit(detect_cvss, url) for url in urls]

    for future in concurrent.futures.as_completed(futures):
        result = future.result()
        if result:
            data.append(result)



#将 URL 和 title 写入 txt 文件
    with open("no_xxxx.txt", 'w') as f:
        for i in data:
            f.write(i + '\n')
            f.close();

 

标签:futures,tuple,URL,关键词,url,import,txt
From: https://www.cnblogs.com/BreakLAC/p/17102404.html

相关文章

  • C#POST请求获取cookie,通过url下载文件
    ///<summary>///请求下载文件///</summary>///<paramname="fileName">传进来的文件名</param>///<returns></returns>pub......
  • 693~694servlet_urlpartten配置 AND HTTP概述
    Servlet相关配置1.Urlpartten:Servlet访问路径1.一个Servlet可以定义多个访问路径:@WebServlet({"/访问1","/"访问2,"/访问3"})2.路径定义的规则:......
  • 非同源url文件下载
    //封装一个download方法constdownloadExcelFile=(path,name)=>{constx=newwindow.XMLHttpRequest();x.open('GET',path,true);x.responseType='blob'......
  • JS获取当前页面 URL 参数方法(转)
    转自:JS获取URL参数方法、js获取当前url中的参数、JS获取URL参数的4种方法总结法一constresult=newURLSearchParams(this.props.location.search);constparam=res......
  • vue项目 前端js实现根据文件url批量压缩下载成zip包
    1.npminstalljszip--save/yarnaddjszip-S2.npminstallfile-saver--save/yarnaddfile-saver-S3.yarnaddaxios以下为完整代码 <template>......
  • url 拼接异常
    异常url:  可以看出拼接了两个url 经排查: 是前端app.js中前端的baseUrl=后拼接的格式异常如下图,少了两个左斜杠,应该为http://192.168.15.102 ......
  • Python模块之 urlparse 拆分 url 网址链接
    作用:拆解url网址链接,协议、网络位置、路径等必要操作:py2:>>>pipinstallurllib-ihttp://pypi.douban.com/simple/--trusted-hostpypi.douban.com>>>fro......
  • 实战:第十二章:txt文件转xml文件
    开发不就这么点事吗,有个啥好bb的controller@RequestMapping("/DataDistributionController")@RestControllerpublicclassDataDistributionController{......
  • Okhttp 如何构建一个 Get 的 URL
    因项目的需要,构建一个微信请求的URL。URL的配置为:https://open.weixin.qq.com/connect/qrconnect?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=......
  • 【原创】淘宝关键词搜索爬取与解析
    本文所有教程及源码、软件仅为技术研究。不涉及计算机信息系统功能的删除、修改、增加、干扰,更不会影响计算机信息系统的正常运行。不得将代码用于非法用途,如侵立删!淘宝......