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 Engines: Comparing ImplementationsJavaScript Engines: Comparing ImplementationsApr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Beyond the Browser: JavaScript in the Real WorldBeyond the Browser: JavaScript in the Real WorldApr 12, 2025 am 12:06 AM

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Apr 11, 2025 am 08:23 AM

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration)How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration)Apr 11, 2025 am 08:22 AM

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript: Exploring the Versatility of a Web LanguageJavaScript: Exploring the Versatility of a Web LanguageApr 11, 2025 am 12:01 AM

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The Evolution of JavaScript: Current Trends and Future ProspectsThe Evolution of JavaScript: Current Trends and Future ProspectsApr 10, 2025 am 09:33 AM

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

Demystifying JavaScript: What It Does and Why It MattersDemystifying JavaScript: What It Does and Why It MattersApr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

Is Python or JavaScript better?Is Python or JavaScript better?Apr 06, 2025 am 12:14 AM

Python is more suitable for data science and machine learning, while JavaScript is more suitable for front-end and full-stack development. 1. Python is known for its concise syntax and rich library ecosystem, and is suitable for data analysis and web development. 2. JavaScript is the core of front-end development. Node.js supports server-side programming and is suitable for full-stack development.

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft