yxw19870806 / Py3CrawlerLib

Py3Crawler common lib

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python Crawler(auto download from website)

Required

  • OS:windows(maybe Linux and mac)
  • Python:v3.6+, not supported Python 2.X

Suggest

  • IDE and Project Encoding setting with UTF-8

Features

  • 多线程
    multithreading
  • 支持使用代理设置
    support proxy
  • 支持绑定键盘事件(快捷键),如暂停/启动程序运行
    support bind keyboard events, e.g. pause or restart process
  • 支持本地端口监听,根据收到的请求内容暂停/启动程序运行
    support local port listener, according to the received content to pause or restart process
  • 支持从本地浏览器中读取cookies并携带访问限制的网站
    read cookies from your local browser
  • 页面访问支持多种参数:
    support multiple parameter for visit web
    • 支持常用请求方法:GET、POST、HEAD、PUT、DELETE、OPTIONS、TRACE
      common request method: GET, POST, HEAD, PUT, DELETE, OPTIONS, TRACE
    • 可自定义添加request header
      add customize request header
    • 可自定义添加Cookies
      add customize cookies
    • 可设置链接超时、读取超时
      set connection timeout and read timeout
    • 可设置是否自动跳转(http code 301、302、303、307、308)
      set whether auto redirect(http code 301, 302, 303, 307, 308)

Install

  • 如果已安装Visual C++ 生成工具和swig(并将swig的安装路径加入系统变量中,否则会提示无法找到swig.exe),请运行install/install.bat
    If you have installed Visual C++ Build Tools and swig for windows (and add swig's install path to your environment variables), you can run install/install.bat

如何安装Visual C++ 生成工具

访问微软官方Visual Studio下载页面
选择"Visual Studio 2017 生成工具"那列的下载
运行下载的exe引导文件、开始安装Visual Studio Installer
Visual Studio Installer安装完毕后,在工作负载标签下选择 'Visual C++生成工具'(点击后右侧默认会有'测试工具核心功能 - 生成工具'+一个对应操作系统的最新版本SDK包)并安装

如何安装swig

访问swig官网下载页面
选择swigwin-X.X.XX(版本号,如swigwin-3.0.12)下载,不要下载源码swig-X.X.XX(如swig-3.0.12)
解压下载的压缩文件到任意目录,并将该目录添加到系统环境变量中(如 D:\swig-3.0.12)

  • (不推荐) 如果未安装Visual C++ 生成工具和swig,请运行install/install.bat
    (Don't suggest) If you haven't installed Visual C++ Build Tools and swig for windows, you can run install/install_whl.bat

Code Structure

  1. 公共类和方法
  • /crawler.py 爬虫父类,多线程爬取父类,异常类
  • /browser.py 浏览器类,获取操作系统中安装的浏览器目录以及保存的cookies
  • /crypto.py 加密解密类,使用基于本计算机信息(MAC+计算机名)的私钥对隐私信息进行AES128加密(如输入的账号、密码)
  • /file.py 文件操作类,读取/写入指定文件
  • /keyboardEvent.py 键盘监听事件类,可以通过指定快捷键暂停/重启/立刻结束爬虫(默认在下一次网络请求时阻塞线程)
  • /log.py 日志记录类,线程安全,4个级别(error、step、trace、notice)的日志记录方法
  • /net.py 网络通信类(基于urllib3),网页访问、资源下载等
  • /output.py 控制台输出类,线程安全
  • /path.py 操作系统路径相关类,创建/删除目录,移动/复制文件或文件夹等操作
  • /portListenerEvent.py 端口监听类,可以通过向指定端口发送请求暂停/重启/立刻结束爬虫(默认在下一次网络请求时阻塞线程)
  • /tool.py 其他一些公共方法类,如符串截取,字符串和列表的转化等
  1. /install,项目依赖的一些扩展包的安装文件(使用pip install)
  2. /processControl,爬虫监听端口发送指定命令

Known Issue

  • install/install_whl.bat 中使用的PyHook(用于在windows中监听鼠标、键盘事件)在python3下有兼容性问题
    如果前台激活了存在非ascii字符的窗口,会抛出异常(类似于 TypeError: KeyboardSwitch() missing 8 required positional arguments: 'msg', 'vk_code', 'scan_code', 'ascii', 'flags', 'time', 'hwnd', and 'win_name')、甚至导致进程退出
    如遇到该问题,可安装Visual C++ 生成工具和swig后使用install/install.bat中的PyHook3替换;或者在config.ini中禁用键盘事件监听功能

About

Py3Crawler common lib


Languages

Language:Python 98.7%Language:Batchfile 1.3%