一个简便方法是使用 site:example.com 查询,然而这种方法对于大战不适用css
builtwith 模块
pip install builtwith
builtwith.parse(url) # returns a dictpython
python-whois 模块
pip install python-whois
import whois
whois.whois(url)json
下载器须要提供的几个功能:浏览器
例子:https://bitbucket.org/wswp/code/src/chpter01/link_crawler3.py缓存
下载的第二步,就是把得到的网页传递给 Extractor 来提取内容,能够经过传递给下载函数回调来处理,可是这种耦合性太强了cookie
书中的缓存把全部相应都作了缓存,包括500的错误响应,实际上这样的直接不缓存好了。。
书中的磁盘缓存把 url normalize 逻辑也加到了这里,感受比较混乱
注意使用磁盘文件缓存的话会受限于磁盘单目录文件的数量,即便是 ext4 文件系统也不大多线程
执行下载时间估算也是很重要的,每一个连接下载须要多长时间,整个过程须要多长时间
多线程的下载例子,手工模拟线程池并发
def process_queue(q): pass threads = [] while thread or crawl_queue: for thread in threads: if not threads.is_alive(): threads.remove(thread) while len(threads) < max_threads and crawl_queue: thread = threading.Thread(target=process_queue, daemon=True) thread.start() threads.append(thread) time.sleep(some_time)
性能的增加与线程和进程的数量并非成线性比例的,而是对数比例,由于切换要花费必定的时间,再者最终是受限于带宽的app
依赖于 Ajax 的网站看起来更复杂,可是实际上由于数据和表现层的分离会更简单,可是若是逆向工程也很差获得通用的方法,如何构建一个辅助工具呢?
表示出网页上哪些地方是动态加载的,列出 js 全局变量,列出可能的 jsonp 请求函数
利用 Ajax 接口时,能够利用各类边界状况,好比把搜索条件置为空,置为 *,置为 .
使用Qt
使用 Selenium 或者 PhantomJS,这时附加 Cookie 等都是很严重的问题
登陆表单中每每会有隐藏的参数,好比 form_key 用于避免表单重复提交,还可能须要 cookie 验证
Wow,居然能够直接从浏览器加载 Cookie,使用 browsercookie 模块
使用机器识别验证码
使用 Pillow 和 pytesseract 识别验证码,可是 tessact 本不是用来识别验证码的
一种锐化方法
img.convert('L') img.point(lambda x: 0 if x < 1 else 255, 'l') tessact.image_to_string(img)
还能够经过限定字符集提升识别率
还可使用人工打码平台