search
HomeWeb Front-endJS TutorialPython crawler browser identification library

This time I will bring you Pythoncrawler browser logo library. What are the precautions for using the Python crawler browser logo library? Here is a practical case. Let’s take a look. .

   UserAgent.py
class toObj(object):
   def init(self, d):
        for a, b in d.items():            if isinstance(b, (list, tuple)):
                setattr(self, a, [toObj(x) if isinstance(
                    x, dict) else x for x in b])            else:
                setattr(self, a, toObj(b) if isinstance(b, dict) else b)                
'''
Android 设备
''' Android = toObj({    "Xiaomi": {        "Id": "Xiaomi",        "Name": "小米手机",        "UserAgent": "Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn;  MI2 Build/JRO03L) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 XiaoMi/MiuiBrowser/1.0"
    },    "Meizu": {        "Id": "Meizu",        "Name": "魅族手机",        "UserAgent": "JUC (Linux; U; 2.3.5; zh-cn; MEIZU MX; 640*960) UCWEB8.5.1.179/145/33232"
    },    "Nexus7": {        "Id": "Nexus7",        "Name": "Nexus 7 (Tablet)",        "UserAgent": "Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166  Safari/535.19"
    },    "AndroidGalaxyS3": {        "Id": "AndroidGalaxyS3",        "Name": "Samsung Galaxy S3 (Handset)",        "UserAgent": "Mozilla/5.0 (Linux; U; Android 4.0.4; en-gb; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"
    },    "AndroidGalaxyTab": {        "Id": "AndroidGalaxyTab",        "Name": "Samsung Galaxy Tab (Tablet)",        "UserAgent": "Mozilla/5.0 (Linux; U; Android 2.2; en-gb; GT-P1000 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
    }
})'''
国产浏览器
'''China = toObj({    "360se": {        "Id": "360se",        "Name": "360安全浏览器",        "UserAgent": "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)"
    },    "360chrome": {        "Id": "360chrome",        "Name": "360极速浏览器",        "UserAgent": "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360Chrome)"
    },    "liebao": {        "Id": "liebao",        "Name": "猎豹浏览器",        "UserAgent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36 LBBROWSER"
    },    "ucpc": {        "Id": "ucpc",        "Name": "UC浏览器电脑版",        "UserAgent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 UBrowser/5.1.2238.18 Safari/537.36"
    },    "uc": {        "Id": "uc",        "Name": "UC浏览器手机版",        "UserAgent": "UCWEB/2.0 (iOS; U; iPh OS 4_3_2; zh-CN; iPh4) U2/1.0.0 UCBrowser/8.6.0.199 U2/1.0.0 Mobile"
    }, "sougou": {        "Id": "sougou",        "Name": "搜狗浏览器",        "UserAgent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 SE 2.X MetaSr 1.0"
    }, "baidu": {        "Id": "baidu",        "Name": "百度浏览器",        "UserAgent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 BIDUBrowser/7.5 Safari/537.36"
    }, "maxthon": {        "Id": "maxthon",        "Name": "遨游浏览器",        "UserAgent": "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)"
    }, "qq": {        "Id": "qq",        "Name": "QQ浏览器",        "UserAgent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36 QQBrowser/9.0.2229.400"
    }, "mqq": {        "Id": "mqq",        "Name": "QQ浏览器手机版",        "UserAgent": "MQQBrowser/3.6/Adr (Linux; U; 4.0.3; zh-cn; HUAWEI U8818 Build/U8818V100R001C17B926;480*800)"
    }, "wechat": {        "Id": "wechat",        "Name": "微信内置浏览器",        "UserAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B329 MicroMessenger/5.0.1"
    }
})'''
搜索引擎浏览器
'''Spider = toObj({    "Baidu": {        "Id": "Baidu",        "Name": "百度PC",        "UserAgent": "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"
    },    "Baidum": {        "Id": "Baidum",        "Name": "百度移动端",        "UserAgent": "Mozilla/5.0 (Linux;u;Android 4.2.2;zh-cn;) AppleWebKit/534.46 (KHTML,like Gecko) Version/5.1 Mobile Safari/10600.6.3 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"
    },    "BingBot": {        "Id": "BingBot",        "Name": "BingBot (Bing's spider)",        "UserAgent": "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
    },    "Googlebot": {        "Id": "Googlebot",        "Name": "Googlebot (Google's spider)",        "UserAgent": "Googlebot/2.1 (+http://www.googlebot.com/bot.html)"
    },    "Slurp": {        "Id": "Slurp",        "Name": "Slurp! (Yahoo's spider)",        "UserAgent": "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)"
    }
})'''
Mac OS
'''Safari = toObj({    "SafariMac": {        "Id": "SafariMac",        "Name": "Safari on Mac",        "UserAgent": "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27"
    },    "SafariWin": {        "Id": "SafariWin",        "Name": "Safari on Windows",        "UserAgent": "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27"
    },    "SafariiPad": {        "Id": "SafariiPad",        "Name": "Safari on iPad",        "UserAgent": "Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3"
    },    "SafariiPhone": {        "Id": "SafariiPhone",        "Name": "Safari on iPhone",        "UserAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3"
    }
})'''
Opera 欧朋
'''Opera = toObj({    "OperaMac": {        "Id": "OperaMac",        "Name": "Opera on Mac",        "UserAgent": "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.9.168 Version/11.52"
    },    "OperaWin": {        "Id": "OperaWin",        "Name": "Opera on Windows",        "UserAgent": "Opera/9.80 (Windows NT 6.1; WOW64; U; en) Presto/2.10.229 Version/11.62"
    }
})'''
Chrome
'''Chrome = toObj({    "ChromeAndroidMobile": {        "Id": "ChromeAndroidMobile",        "Name": "Chrome on Android Mobile",        "UserAgent": "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19"
    },    "ChromeAndroidTablet": {        "Id": "ChromeAndroidTablet",        "Name": "Chrome on Android Tablet",        "UserAgent": "Mozilla/5.0 (Linux; Android 4.1.2; Nexus 7 Build/JZ054K) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19"
    },    "ChromeMac": {        "Id": "ChromeMac",        "Name": "Chrome on Mac",        "UserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36"
    },    "ChromeUbuntu": {        "Id": "ChromeUbuntu",        "Name": "Chrome on Ubuntu",        "UserAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Ubuntu/11.10 Chromium/27.0.1453.93 Chrome/27.0.1453.93 Safari/537.36"
    },    "ChromeWin": {        "Id": "ChromeWin",        "Name": "Chrome on Windows",        "UserAgent": "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36"
    },    "ChromeiPhone": {        "Id": "ChromeiPhone",        "Name": "Chrome on iPhone",        "UserAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_4 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) CriOS/27.0.1453.10 Mobile/10B350 Safari/8536.25"
    }
})'''
IE
'''IE = toObj({    "IE10": {        "Id": "IE10",        "Name": "Internet Explorer 10",        "UserAgent": "Mozilla/5.0 (compatible; WOW64; MSIE 10.0; Windows NT 6.2)"
    },    "IE6": {        "Id": "IE6",        "Name": "Internet Explorer 6",        "UserAgent": "Mozilla/4.0 (Windows; MSIE 6.0; Windows NT 5.2)"
    },    "IE7": {        "Id": "IE7",        "Name": "Internet Explorer 7",        "UserAgent": "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
    },    "IE8": {        "Id": "IE8",        "Name": "Internet Explorer 8",        "UserAgent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)"
    },    "IE9": {        "Id": "IE9",        "Name": "Internet Explorer 9",        "UserAgent": "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
    }
})'''
Firefox
'''Firefox = toObj({    "FFAndroidHandset": {        "Id": "FFAndroidHandset",        "Name": "Firefox on Android Mobile",        "UserAgent": "Mozilla/5.0 (Android; Mobile; rv:14.0) Gecko/14.0 Firefox/14.0"
    },    "FFAndroidTablet": {        "Id": "FFAndroidTablet",        "Name": "Firefox on Android Tablet",        "UserAgent": "Mozilla/5.0 (Android; Tablet; rv:14.0) Gecko/14.0 Firefox/14.0"
    },    "FFMac": {        "Id": "FFMac",        "Name": "Firefox on Mac",        "UserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0"
    },    "FFUbuntu": {        "Id": "FFUbuntu",        "Name": "Firefox on Ubuntu",        "UserAgent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:21.0) Gecko/20130331 Firefox/21.0"
    },    "FFWin": {        "Id": "FFWin",        "Name": "Firefox on Windows",        "UserAgent": "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0"
    }
})'''
Windows Phone
'''WinPhone = toObj({    "Win7Phone": {        "Id": "Win7Phone",        "Name": "Windows Phone 7",        "UserAgent": "Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; LG; GW910)"
    },    "Win75Phone": {        "Id": "Win75Phone",        "Name": "Windows Phone 7.5",        "UserAgent": "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG; SGH-i917)"
    },    "Win8Phone": {        "Id": "Win8Phone",        "Name": "Windows Phone 8",        "UserAgent": "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)"
    }
})'''
iOS
'''iOS = toObj({    "iPad": {        "Id": "iPad",        "Name": "iPad",        "UserAgent": "Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3"
    },    "iPhone": {        "Id": "iPhone",        "Name": "iPhone",        "UserAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3"
    },    "iPod": {        "Id": "iPod",        "Name": "iPod",        "UserAgent": "Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A101a Safari/419.3"
    }
})
Other = toObj({    "BlackBerry": {        "Id": "BlackBerry",        "Name": "BlackBerry - Playbook 2.1",        "UserAgent": "Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML, like Gecko) Version/7.2.1.0 Safari/536.2+"
    },    "MeeGo": {        "Id": "MeeGo",        "Name": "MeeGo - Nokia N9",        "UserAgent": "Mozilla/5.0 (MeeGo; NokiaN9) AppleWebKit/534.13 (KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13"
    }
})

Default = Chrome.ChromeWin.UserAgent

Use:

import  UserAgent as uaimport requests
print("默认标识",ua.Default)
print("小米标识",ua.Android.Xiaomi.UserAgent)
_headers={    'Accept-Language': 'zh-CN,zh;q=0.8',    'Content-Type': 'text/html;Charset=utf-8',    "User-Agent":ua.Android.Xiaomi.UserAgent
}
rd = requests.get("http://www.jianshu.com/", params=None, headers=_headers)
rd.encoding = 'utf-8'print(rd.text)

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related matters on the php Chinese website article!

Related reading:

Nodejs How to use http module to write upload image interface test client

h5 Make performance change line chart

The above is the detailed content of Python crawler browser identification library. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
JavaScript's Core: Is It Built on C or C  ?JavaScript's Core: Is It Built on C or C ?May 05, 2025 am 12:07 AM

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript Applications: From Front-End to Back-EndJavaScript Applications: From Front-End to Back-EndMay 04, 2025 am 12:12 AM

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Python vs. JavaScript: Which Language Should You Learn?Python vs. JavaScript: Which Language Should You Learn?May 03, 2025 am 12:10 AM

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

JavaScript Frameworks: Powering Modern Web DevelopmentJavaScript Frameworks: Powering Modern Web DevelopmentMay 02, 2025 am 12:04 AM

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

The Relationship Between JavaScript, C  , and BrowsersThe Relationship Between JavaScript, C , and BrowsersMay 01, 2025 am 12:06 AM

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js Streams with TypeScriptNode.js Streams with TypeScriptApr 30, 2025 am 08:22 AM

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

Python vs. JavaScript: Performance and Efficiency ConsiderationsPython vs. JavaScript: Performance and Efficiency ConsiderationsApr 30, 2025 am 12:08 AM

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

The Origins of JavaScript: Exploring Its Implementation LanguageThe Origins of JavaScript: Exploring Its Implementation LanguageApr 29, 2025 am 12:51 AM

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools