crawlerdetect是一个python类,用于通过用户代理检测bots/crawler/spider。

crawlerdetect的Python项目详细描述


关于crawlerdetect

crawlerdetect是php类@CrawlerDetect的python版本。

它有助于通过用户代理和其他http头检测bots/crawler/spider。目前能够检测到1000个机器人/蜘蛛/爬虫。

安装

运行pip install crawlerdetect

使用量

变型1

fromcrawlerdetectimportCrawlerDetectcrawler_detect=CrawlerDetect()crawler_detect.isCrawler('Mozilla/5.0 (compatible; Sosospider/2.0; +http://help.soso.com/webspider.htm)')# true if crawler user agent detected

变型2

fromcrawlerdetectimportCrawlerDetectcrawler_detect=CrawlerDetect(user_agent='Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit (KHTML, like Gecko) Mobile (compatible; Yahoo Ad monitoring; https://help.yahoo.com/kb/yahoo-ad-monitoring-SLN24857.html)')crawler_detect.isCrawler()# true if crawler user agent detected

变型3

fromcrawlerdetectimportCrawlerDetectcrawler_detect=CrawlerDetect(headers={'DOCUMENT_ROOT':'/home/test/public_html','GATEWAY_INTERFACE':'CGI/1.1','HTTP_ACCEPT':'*/*','HTTP_ACCEPT_ENCODING':'gzip, deflate','HTTP_CACHE_CONTROL':'no-cache','HTTP_CONNECTION':'Keep-Alive','HTTP_FROM':'googlebot(at)googlebot.com','HTTP_HOST':'www.test.com','HTTP_PRAGMA':'no-cache','HTTP_USER_AGENT':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36','PATH':'/bin:/usr/bin','QUERY_STRING':'order=closingDate','REDIRECT_STATUS':'200','REMOTE_ADDR':'127.0.0.1','REMOTE_PORT':'3360','REQUEST_METHOD':'GET','REQUEST_URI':'/?test=testing','SCRIPT_FILENAME':'/home/test/public_html/index.php','SCRIPT_NAME':'/index.php','SERVER_ADDR':'127.0.0.1','SERVER_ADMIN':'webmaster@test.com','SERVER_NAME':'www.test.com','SERVER_PORT':'80','SERVER_PROTOCOL':'HTTP/1.1','SERVER_SIGNATURE':'','SERVER_SOFTWARE':'Apache','UNIQUE_ID':'Vx6MENRxerBUSDEQgFLAAAAAS','PHP_SELF':'/index.php','REQUEST_TIME_FLOAT':1461619728.0705,'REQUEST_TIME':1461619728})crawler_detect.isCrawler()# true if crawler user agent detected

输出匹配的bot的名称(如果有的话)

fromcrawlerdetectimportCrawlerDetectcrawler_detect=CrawlerDetect()crawler_detect.isCrawler('Mozilla/5.0 (compatible; Sosospider/2.0; +http://help.soso.com/webspider.htm)')# true if crawler user agent detectedcrawler_detect.getMatches()# Sosospider

贡献

如果发现crawler detect无法检测的bot/spider/crawler用户代理,请使用添加到providers/crawlers.py中的数组的regex模式提交一个pull请求,并将失败的用户代理添加到tests/crawlers.txt

如果失败,只需使用您找到的用户代理创建一个问题,我们将从中解决:)

ES6库

要将此库与nodejs或任何基于es6应用程序的库一起使用,请签出es6-crawler-detect

.net库

要在基于.NET标准(包括.NET核心)的项目中使用此库,请签出NetCrawlerDetect

净值扩展

要将此库与nette框架一起使用,请签出NetteCrawlerDetect

红宝石

要将这个库与ruby on rails或任何基于ruby的应用程序一起使用,请查看crawler_detectgem。

这个类的部分基于出色的MobileDetect

Analytics

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
无JPA的纯Hibernate ORM java SpringBoot配置   安卓会生成一组唯一的java数字   java我的自定义阵列列表每次启动时都会崩溃我不确定为什么会一直崩溃   Java继承;将子类传递给超类的抽象方法   java从没有if语句的数组中获取instanceof type   java中使用对象的温度转换   存储库接口的JavaSpringDataMongoDBeanXML配置   java JAXWS为iBM websphere、iBM web服务客户端添加寻址   数组试图返回Java中两个对象的面积之和   apache Spark java:columnNameOfCorruptRecord和badRecordsPath在加载csv时不工作   java无法创建。txt文件   java Hibernate与MySQL插入查询不一致   不考虑java Hazelcast分布式地图的最大大小   bash Java如何在父进程中设置环境变量