useragent pool. Note: You must set it in settings. py. "Import randomfrom scrapy. contrib. downloadermiddleware. useragent import UserAgentMiddlewareclass RotateUserAgentMiddleware (UserAgentMiddleware): def _ init _ (self, user_agent = ''): self. user_agent = user_agent def process_request (self, request, spider): ua = random. choice (self. user_agent_list) if ua: # display the currently used
Let's look at the source of jquery:
The code is as follows
Copy Code
var useragent = Navigator.userAgent.toLowerCase ();Figure out what browser is being usedJquery.browser = {Version: (Useragent.match (/.+ (?: Rv|it|ra|ie) [/:] ([D.] +)/ ) || []) [1],Safari:/webkit/.test (useragent),Opera:/opera/.test (useragent),MSIE:/msie/.test (
to accurately determine what kind of browser or even version the user is using. Good developers want to know some of their implementation mechanisms, so how does jQuery do that?
View the latest source code for JQuery (version 1.2.2), in line 1195th to 1205, is its function of judging the browser. As you can see, JQuery uses the second method described above, which uses user-agent to determine the user's browser and version.
To be honest, at first I was amazed at the type and version of the br
browsers, and the other is to judge by analyzing the userAgent attributes of the browser. In many cases, after determining the browser type, you must determine the browser version to handle compatibility issues. However, you can only determine the browser version by analyzing the browser's userAgent.
Let's analyze the features of various browsers and Their userAgent
Javascript: use JavaScript to detect browser-related features. Javascript tutorial
I. Check the browser nameProblem:Different browsers have different standard support for javascript. Sometimes you want the script to run well on different browsers. In this case, you need to check the browser and determine its name, write scripts for different browsers.Solution:Use the appName attribute of the navigator object.For example, to check whether the browser is IE, you can do this:Var isIE = (navigator.
Records of Baidu,google,bing,yahoo,soso,sogou,yodao crawling sites can be recorded
The code is as follows:01
//http://www.tongqiong.com03function Get_naps_bot ()24905$useragent = Strtolower ($_server[' http_user_agent ');0607if (Strpos ($useragent, ' Googlebot ')!== false) {08return ' Google ';09}1011if (Strpos ($useragent, ' Baiduspider ')!== false) {12return '
Check the browser version information or browsers. We can determine the user's user-agent features. Next, I will only introduce the inspection of four mainstream browsers. other browsers can be automatically added.
Let's take a look at the user-agent of the following four mainstream browsers:
Safari (Windows edition)
... AppleWebKit/523.12.9 (KHTML, like Gecko) Version/3.0 Safari/523.12.9Opera (Opera 9.2 on Windows XP)
Opera/9.24 (Windows NT 5.1; U; zh-cn)Mozilla (Firefox 2.0.11 on Windows XP)
.
Determining search engine spider crawlers is actually very simple. You only need to determine the source useragent and then check whether there are any strings specified by search engine spider. Next let's take a look at the php Method for Determining search engine spider crawlers, I hope this tutorial will help you. Determining search engine spider crawlers is actually very simple. You only need to determine the source
IeOnly IE supports the creation of ActiveX controls, so she has something that other browsers do not have, which is the ActiveXObject function. As long as the Window object exists ActiveXObject function, it can be clearly determined that the current browser is ie. The typical useragent for each version of IE are as follows:mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2)mozilla/4.0 (compatible; MSIE
Copy Code code as follows:
var $mfunc =function () {
return {
This function determines the browser type and, for simplicity, returns a numeric representation,
1.ie6;2.ie7; 3.ie8;4.ie5.5;5,firefox;6.chrome;7.opera;8.safari;0. Browsers that cannot be detected
Other browsers can add themselves
Whichos:function () {
var useragent=navigator.useragent.tolowercase ();
Return (/msie 6/i.test (useragent)
How to use:
$.browser. [' Browser keyword ']
Copy Code code as follows:
$ (function () {
if ($.browser.msie) {
Alert ("This is Msie");
}
else if ($.browser.safari)
{
Alert ("This is safari!");
}
else if ($.browser.mozilla)
{
Alert ("This is mozilla!");
}
else if ($.browser.opera) {
Alert ("This is opera");
}
else {
Alert ("I don ' t konw!");
}
Let's look at the source of jquery:
Copy Code code as follows:
var
-agent for the specified domain name precedence over the $curl_default_configThe default use of Baidu Spider UA, refused to Baidu UA site very fewEg: $useragent _config = Array (' Web_domain ' => ' User agent ',' www.xxx.com ' => ' mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; trident/4.0) ');*/$useragent _config = Array (' hiphotos.baidu.com ' => ' mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; tr
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.