基于python编写简单的web目录扫描(随机ua,随机代理ip)脚本

基于python编写简单的web目录扫描(随机ua,随机代理ip)脚本

随便看看吧,
记录编写脚本过程。
核心代码如下,后期再优化多线程:

import requests
import random
#自定义url
url = 'http://www.baidu.com'
#随机ua
user_agent_list = [

    # Firefox
    "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0",
    "Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.10) Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.10",
    # Safari
    "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
    # QQ浏览器
    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0)",
]
url_agent = random.choice(user_agent_list)
#代理池,可添加
porxy_list = {
    "http":"http://127.0.0.1:7890"

}
#请求头
headers = {
    "User-Agent":url_agent
}

url_list =[]
if dir =="":
    #自定义字典
    dir = "test.txt"
try:
    with open("test.txt",'r')as f:
        for a in f:
            a = a.replace('\n','')
            url_list.append(a)
        f.close()
except Exception as e:
    print(e)
for data in url_list:
    dst_url = url + data
    try:
        response = requests.get(dst_url,headers=headers,proxies=porxy_list)
        print("%s-----%s" %(dst_url,response))
    except Exception as e:
        print("%s-----%s" %(dst_url,e))



结果如下:
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值