Java通过浏览器请求头(User-Agent)获取 浏览器类型,操作系统类型,手机机型

User Agent中文名为用户代理,简称 UA,它是一个特殊字符串头,使得服务器能够识别客户使用的操作系统及版本、CPU 类型、浏览器及版本、浏览器渲染引擎、浏览器语言、浏览器插件等。

一些网站常常通过判断 UA 来给不同的操作系统、不同的浏览器发送不同的页面,因此可能造成某些页面无法在某个浏览器中正常显示,但通过伪装 UA 可以绕过检测。

一:获得浏览器请求头中的User-Agent

String ua = request.getHeader("User-Agent")

二:获得浏览器类型,操作系统类型:(注意,UserAgent类在UserAgentUtils.jar中,自行下载)

    UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
           Browser browser = userAgent.getBrowser();
           OperatingSystem os = userAgent.getOperatingSystem();  

三:获得手机类型:

方案一:正则表达式

通过观察规律,得出以下表达式:

;\s?([^;]+?)\s?(Build)?/  

Java代码:

    Pattern pattern = Pattern.compile(";\\s?(\\S*?\\s?\\S*?)\\s?(Build)?/");
                Matcher matcher = pattern.matcher(userAgent);
                String model = null;
                if (matcher.find()) {
                    model = matcher.group(1).trim();
                    log.debug("通过userAgent解析出机型:" + model);
                }  

以下为部分UserAgent,供测试,可以直接在EditPlus里验证。

Mozilla/5.0 (Linux; U; Android 4.3; zh-cn; R8007 Build/JLS36C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
Mozilla/5.0 (Linux; U; Android 4.3; zh-cn; R8007 Build/JLS36C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 V1_AND_SQ_5.0.0_146_YYB_D QQ/5.0.0.2215
Mozilla/5.0 (Linux; U; Android 4.3; zh-cn; SM-N9009 Build/JSS15J) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.3 Mobile Safari/537.36
Mozilla/5.0 (Linux; Android 4.2.2; zh-cn; SCH-I959 Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Version/1.0 Chrome/18.0.1025.308 Mobile Safari/535.19
Mozilla/5.0 (Linux; U; Android 4.3; zh-CN; SM-N9009 Build/JSS15J) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.9.2.467 U3/0.8.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; U; Android 4.1.2; zh-CN; Coolpad 5891 Build/JZO54K) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.9.3.478 U3/0.8.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; U; Android 4.1.2; zh-cn; Coolpad 5891 Build/JZO54K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 V1_AND_SQ_5.0.0_146_YYB2_D QQ/5.0.0.2215
Mozilla/5.0 (iPhone; CPU iPhone OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53
Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257 QQ/5.0.0.165
Mozilla/5.0 (Linux; Android 4.3; zh-cn; SAMSUNG-GT-I9308_TD/1.0 Android/4.3 Release/11.15.2013 Browser/AppleWebKit534.30 Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; GT-N7100 Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 SogouMSE,SogouMobileBrowser/3.2.3
Mozilla/5.0 (Linux; U; Android 4.2.2; zh-cn; SCH-I959 Build/JDQ39) AppleWebKit/534.24 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.24 T5/2.0 baidubrowser/5.0.3.10 (Baidu; P1 4.2.2)
Mozilla/5.0 (Linux; U; Android 4.2.2; zh-cn; SCH-I959 Build/JDQ39) AppleWebKit/534.24 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.24 T5/2.0
Mozilla/5.0 (Linux; Android 4.3; SM-N9009 Build/JSS15J) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.117 Mobile Safari/537.36 OPR/24.0.1565.82529
Mozilla/5.0 (Linux; U; Android 4.4.4; zh-CN; Nexus 4 Build/KTU84P) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.9.2.467 U3/0.8.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; U; Android 4.0.4; zh-cn; HUAWEI C8825D Build/HuaweiC8825D) AppleWebKit/534.24 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.24 T5/2.0 baidubrowser/5.2.3.0 (Baidu; P1 4.0.4)
Mozilla/5.0 (Linux; U; Android 4.0.4; zh-cn; HUAWEI C8825D Build/HuaweiC8825D) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.3 Mobile Safari/537.36
Mozilla/5.0 (Linux; Android 4.0.4; HUAWEI C8825D Build/HuaweiC8825D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.117 Mobile Safari/537.36
Mozilla/5.0 (Linux; U; Android 4.0.4; zh-cn; HUAWEI C8825D Build/HuaweiC8825D) AppleWebKit/535.19 (KHTML, like Gecko) Version/4.0 LieBaoFast/2.12.0 Mobile Safari/535.19
Opera/9.80 (Android; Opera Mini/7.0.31907/34.2499; U; zh) Presto/2.8.119 Version/11.10
Mozilla/5.0 (Linux; U; Android 4.0.4; zh-cn; HW-HUAWEI_C8825D/C8825DV100R001C92B943SP01; 480*800; CTC/2.0) AppleWebKit/534.30 Mobile Safari/534.30
Mozilla/5.0 (Linux; U; Android 4.4.2; zh-CN; SGP521 Build/17.1.2.A.0.314) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.9.2.467 U3/0.8.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; Android 4.4.2; SGP521 Build/17.1.2.A.0.314) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.117 Safari/537.36
Mozilla/5.0 (Linux; U; Android 4.0.4; zh-CN; HUAWEI C8825D Build/HuaweiC8825D) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.8.5.442 U3/0.8.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; GT-N7100 Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
Mozilla/5.0 (Linux; Android 4.4.2; zh-cn; SAMSUNG-SM-N9009 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.5 Chrome/28.0.1500.94 Mobile Safari/537.36
Mozilla/5.0 (Linux; U; Android 4.2.2; zh-CN; HTC HTL22 Build/JDQ39) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.9.2.467 U3/0.8.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; Android 4.3; SM-N9009 Build/JSS15J) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.117 Mobile Safari/537.36
Mozilla/5.0 (Linux; U; Android 4.2.1; zh-cn; AMOI A920W Build/JOP40D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
Mozilla/5.0 (Linux; Android 4.3; SM-N9009 Build/JSS15J) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.135 Mobile Safari/537.36
Mozilla/5.0 (Linux; U; Android 4.1.1; zh-CN; GT-N7100 Build/JRO03C) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.9.2.467 U3/0.8.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; U; Android 4.3; zh-cn; R8007 Build/JLS36C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
Huawei U8800 	Android 2.3.3 	Baidu 2.2 	Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn) AppleWebKit/530.17 (KHTML, like Gecko) FlyFlow/2.2 Version/4.0 Mobile Safari/530.17 		有用(0)
Huawei U8800 	Android 2.3.3 	UC 8.7 	Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; U8800 Build/HuaweiU8800) UC AppleWebKit/534.31 (KHTML, like Gecko) Mobile Safari/534.31 		有用(0)
Meizu MX M031 	Android 4.0.3 	Chrome 18 	Mozilla/5.0 (Linux; Android 4.0.3; M031 Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19 		有用(0)
Meizu MX M031 	Android 4.0.3 	Opera 12.1 	Opera/9.80 (Android 4.0.3; Linux; Opera Mobi/ADR-1210241511) Presto/2.11.355 Version/12.10 		有用(0)
Meizu MX M031 	Android 4.0.3 	-built-in * 	Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M031 Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 		有用(0)
Meizu MX M031 	Android 4.0.3 	Baidu 2.2 	Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn) AppleWebKit/530.17 (KHTML, like Gecko) FlyFlow/2.2 Version/4.0 Mobile Safari/530.17 		有用(0)
Meizu MX M031 	Android 4.0.3 	UC 8.7 	Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M031 Build/IML74K) UC AppleWebKit/534.31 (KHTML, like Gecko) Mobile Safari/534.31 		有用(0)
Meizu M9 	Android 4.0.3 	QQ 3.7 	MQQBrowser/3.7/Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M9 Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 	Normal Mode 	有用(0)
Meizu M9 	Android 4.0.3 	QQ 3.5 	MQQBrowser/3.5/Adr (Linux; U; 4.0.3; zh-cn; M9 Build/Flyme 1.0.1;640*960) 	Speed Mode 	有用(0)
Meizu M9 	Android 4.0.3 	-built-in * 	Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M9 Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 		有用(0)
Meizu M9 	Android 4.0.3 	QQ 3.5 	MQQBrowser/3.5/Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M9 Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 	Normal Mode 	有用(0)
Meizu MX M031 	Android 4.0.3 	Maxthon 2.7 	Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M031 Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 		有用(0)
Huawei U8800 	Android 2.3.3 	Maxthon 2.7 	Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; U8800 Build/HuaweiU8800) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 		有用(0)
Huawei U8800 	Android 2.3.3 	QQ 3.7 	MQQBrowser/3.7/Adr (Linux; U; 2.3.5; zh-cn; U8800 Build/U8800V100R001C00B528G002;480*800) 	Speed Mode 	有用(0)
Huawei U8800 	Android 2.3.3 	Dolphin 9.1 	Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; U8800 Build/HuaweiU8800) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 		有用(0)
Huawei U8800 	Android 2.3.3 	QQ 3.7 	MQQBrowser/3.7/Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; U8800 Build/HuaweiU8800) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 	Normal Mode 	有用(0)
Huawei U8800 	Android 2.3.3 	-built-in * 	Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; U8800 Build/HuaweiU8800) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Samsung P6200(GALAXY Tab) 	Android 3.2 	-built-in * 	Mozilla/5.0 (Linux; U; Android 3.2; zh-cn; GT-P6200 Build/HTJ85B) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13 		有用(0)
Huawei U8800 	Android 2.3.3 	Maxthon 4.0 	Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; U8800 Build/HuaweiU8800) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 		有用(0)
Meizu MX M031 	Android 4.0.3 	Baidu 2.3 	Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M031 Build/IML74K) AppleWebKit/530.17 (KHTML, like Gecko) FlyFlow/2.3 Version/4.0 Mobile Safari/530.17 baidubrowser/023_1.41.3.2_diordna_069_046/uzieM_51_3.0.4_130M/1200a/963E77C7DAC3FA587DF3A7798517939D%7C408994110686468/1 		有用(0)
Huawei U8800 	Android 2.3.3 	Baidu 2.3 	Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; U8800 Build/HuaweiU8800) AppleWebKit/530.17 (KHTML, like Gecko) FlyFlow/2.3 Version/4.0 Mobile Safari/530.17 baidubrowser/042_1.6.3.2_diordna_008_084/IEWAUH_01_5.3.2_0088U/1001a/BE44DF7FABA8768B2A1B1E93C4BAD478%7C898293140340353/1 		有用(0)
Huawei U8800 	Android 2.3.3 	Dolphin 9.2 	Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; U8800 Build/HuaweiU8800) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 		有用(0)
HTC S720e(One X) 	Android 4.0.3 	-built-in * 	Mozilla/5.0 (Linux; U; Android 4.0.4; zh-cn; HTC S720e Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 		有用(1)
HTC S720e(One X) 	Android 4.0.3 	UC 8.7 	Mozilla/5.0 (Linux; U; Android 4.0.4; zh-cn; HTC S720e Build/IMM76D) UC AppleWebKit/534.31 (KHTML, like Gecko) Mobile Safari/534.31 		有用(0)
Meizu MX M031 	Android 4.0.3 	Dolphin Min 2.3 	Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M031 Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 		有用(0)
Meizu MX M031 	Android 4.0.3 	QQ 4.0 	MQQBrowser/4.0/Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; M031 Build/IML74K) AppleWebKit/533.1 (KHTML, like Gecko) Mobile Safari/533.1 		有用(0)
Meizu M9 	Android 4.0.3 	QQ 3.7 	MQQBrowser/3.7/Adr (Linux; U; 4.0.3; zh-cn; M9 Build/Flyme 1.0.1;640*960)
Meizu MX2 M040 	Android 4.1 	UC 9.4 	Mozilla/5.0 (Linux; U; Android 4.1.1; zh-CN; M040 Build/JRO03H) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.4.1.362 U3/0.8.0 Mobile Safari/533.1 		有用(0)
Meizu MX2 M040 	Android 4.1 	Chrome 31 	Mozilla/5.0 (Linux; Android 4.1.1; M040 Build/JRO03H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36 		有用(0)
Meizu MX2 M040 	Android 4.1 	猎豹 2.8 	Mozilla/5.0 (Linux; Android 4.1.1; M040 Build/JRO03H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.64 Mobile Safari/537.36 		有用(0)
Meizu MX2 M040 	Android 4.1 	Baidu 4.1 	Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; M040 Build/JRO03H) AppleWebKit/534.24 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.24 T5/2.0 baidubrowser/4.2.4.0 (Baidu; P1 4.1.1) 		有用(0)
Meizu MX M031 	Android 4.1 	-built-in * 	Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; M031 Build/JRO03H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 		有用(1)
Meizu MX M031 	Android 4.1 	UC 8.8 	Mozilla/5.0 (Linux; U; Android 4.1.1; zh-CN; M031 Build/JRO03H) AppleWebKit/534.31 (KHTML, like Gecko) UCBrowser/8.8.3.278 U3/0.8.0 Mobile Safari/534.31 		有用(0)
Meizu MX2 M040 	Android 4.1 	QQ 4.1 	Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; M040 Build/JRO03H) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/4.1 Mobile Safari/533.1 		有用(0)
Meizu MX2 M040 	Android 4.1 	-built-in * 	Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; M040 Build/JRO03H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 		有用(2)
Samsung P6200(GALAXY Tab) 	Android 3.2 	QQ HD 2.1 	Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 		有用(0)
Samsung P6200(GALAXY Tab) 	Android 3.2 	UC HD 2.3 	Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3) AppleWebKit/534.31 (KHTML, like Gecko) Chrome/17.0.558.0 Safari/534.31 UCBrowser/2.3.1.257

通过验证,成功率95%以上。

方案二:开源类库WURFL

地址:http://wurfl.sourceforge.net/apis.php

在线测试地址:http://tools.scientiamobile.com/

时间: 2024-11-05 13:04:08

Java通过浏览器请求头(User-Agent)获取 浏览器类型,操作系统类型,手机机型的相关文章

接口测试——HttpClient工具的https请求、代理设置、请求头设置、获取状态码和响应头

转自:https://www.cnblogs.com/hong-fithing/p/7617855.html https请求 https协议(Secure Hypertext Transfer Protocol) : 安全超文本传输协议, HTTPS以保密为目标研发, 简单讲HTTPS协议是由SSL+HTTP协议构建的可进行加密传输. 身份认证的网络协议, 其安全基础是SSL协议, 因此加密的详细内容请看SSL. 全称Hypertext Transfer Protocol overSecure

selenium.Phantomjs设置浏览器请求头

from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities #设置浏览器请求头 dcap = dict(DesiredCapabilities.PHANTOMJS) dcap["phantomjs.page.settings.userAgent"] =( "Mozilla/5.0 (Linux; Android 5.1

修改浏览器请求头插件Modify Headers

使用Modify Headers修改或增加请求头 添加后再次访问任何网站都会带有已添加的headers 备注:今天刚学的东西: 出现某些请求一下就消失的情况 可以勾选这个选项来抓取: 原文地址:https://www.cnblogs.com/zhangzimo/p/11739336.html

fetch跨域浏览器请求头待研究

fetch('https://wwww.baidu.com', {headers: { "Access-Control-Allow-Origin": "*", 'Access-Control-Allow-Methods': 'GET, POST, PATCH, PUT, DELETE, OPTIONS', 'Access-Control-Allow-Headers': 'Origin, Content-Type, X-Auth-Token'}}) 原文地址:http

HTTP 协议 请求头详解

HTTP由两部分组成:请求和响应.当你在Web浏览器中输入一个URL时,浏览 器将根据你的要求创建并发送请求,该请求包含所输入的URL以及一些与浏览器本身相关的信息.当服务器收到这个请求时将返回一个响应,该响应包括与该请求 相关的信息以及位于指定URL(如果有的话)的数据.直到浏览器解析该响应并显示出网页(或其他资源)为止. HTTP请求 HTTP请求的格式如下所示: <request-line><headers><blank line>[<request-bod

http请求头

GET / HTTP/1.1 Host:  www.baidu.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050225 Firefox/1.0.1 Connection: Keep-Alive POST / HTTP/1.1 Host:  www.baidu.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en

Http消息头中常用的请求头和响应头

作为Web开发对常用http的请求头和响应头熟悉了解一下还是很有必要的.比如请求头中Content-type指定了请求的内容,若类型是application/x-www-form-urlencoded,就可以调用reqeust的获取参数方法取到内容,若是其它都需要调用获取流的方法获取.又比如响应头X-Frame-Options 的设置直接决定了你的页面是否能被其它非同源的ifream嵌入,而这个设置可以是在html页面中,也可以是框架或代码的响应头设置中,也可以是在http服务器(nginx或t

python3爬虫中文乱码之请求头‘Accept-Encoding’:br 的问题

当用python3做爬虫的时候,一些网站为了防爬虫会设置一些检查机制,这时我们就需要添加请求头,伪装成浏览器正常访问. header的内容在浏览器的开发者工具中便可看到,将这些信息添加到我们的爬虫代码中即可. 'Accept-Encoding':是浏览器发给服务器,声明浏览器支持的编码类型.一般有gzip,deflate,br 等等. python3中的 requests包中response.text 和 response.content response.content #字节方式的响应体,会

一次完整的浏览器请求流程(转)

一次完整的浏览器请求流程 当我们在浏览器的地址栏输入 www.linux178.com ,然后回车,回车这一瞬间到看到页面到底发生了什么呢?整个流程如下: 域名解析 --> 发起TCP的3次握手 --> 建立TCP连接后发起http请求 --> 服务器响应http请求,浏览器得到html代码 --> 浏览器解析html代码,并请求html代码中的资源(如js.css.图片等) --> 浏览器对页面进行渲染呈现给用户 以下就是上面过程的一一分析,我们就以Chrome浏览器为例: