Open ghost opened 2 years ago
通过以下源码发现一个问题:
import HackRequests hack = HackRequests.hackRequests() url_str = "http://localhost/" rsp = hack.http(url=url_str) print(f'''首次获取日志:{rsp.log}''') print(f'''获取网页内容:{rsp.text()}''') print(f'''再次获取日志:{rsp.log}''')
运行结果:
首次获取日志:{'request': 'GET / HTTP/1.1\r\nHost: localhost\r\nAccept-Encoding: gzip, deflate\r\nConnection: close\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36', 'response': 'HTTP/1.1 200 OK\r\nDate: Fri, 05 Aug 2022 02:01:07 GMT\nServer: Apache/2.4.39 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9a mod_log_rotate/1.02\nLast-Modified: Tue, 03 Sep 2019 06:30:48 GMT\nETag: "903-591a03aa15600"\nAccept-Ranges: bytes\nContent-Length: 2307\nConnection: close\nContent-Type: text/html\n\n', 'url': 'http://localhost/'} 获取网页内容:<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <title>站点创建成功-phpstudy for windows</title> <meta name="keywords" content=""> <meta name="description" content=""> <meta name="renderer" content="webkit"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="format-detection" content="telephone=no"> <meta HTTP-EQUIV="pragma" CONTENT="no-cache"> <meta HTTP-EQUIV="Cache-Control" CONTENT="no-store, must-revalidate"> <meta HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT"> <meta HTTP-EQUIV="expires" CONTENT="0"> <style> body{ font: 16px arial,'Microsoft Yahei','Hiragino Sans GB',sans-serif; } h1{ margin: 0; color:#3a87ad; font-size: 26px; } .content{ width: 45%; margin: 0 auto; } .content >div{ margin-top: 200px; padding: 20px; background: #d9edf7; border-radius: 12px; } .content dl{ color: #2d6a88; line-height: 40px; } .content div div { padding-bottom: 20px; text-align:center; } </style> </head> <body> <div class="content"> <div> <h1>站点创建成功</h1> <dl> <dt>目录说明:</dt> <dd>1:网站目录:/phpstudy安装目录/www/站点域名/</dd> <dd>2:错误提示页面:/phpstudy安装目录/www/站点域名/error/</dd> <dd>3:你可以删除或者修改该目录下的所有文件</dd> <dt>操作注意事项:</dt> <dd>1:新建站点、数据库、FTP可在phpstudy面板操作,数据库可在环境中下载数据库管理软件等;</dd> <dd>2:将网站程序放到站点目录时请使用复制,剪切可能造成程序文件权限不正确;</dd> </dl> <div>使用手册,视频教程,BUG反馈,官网地址: <a href="https://www.xp.cn" target="_blank">www.xp.cn</a> </div> </div> </div> </body> </html> 再次获取日志:{'request': 'GET / HTTP/1.1\r\nHost: localhost\r\nAccept-Encoding: gzip, deflate\r\nConnection: close\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36', 'response': 'HTTP/1.1 200 OK\r\nDate: Fri, 05 Aug 2022 02:01:07 GMT\nServer: Apache/2.4.39 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9a mod_log_rotate/1.02\nLast-Modified: Tue, 03 Sep 2019 06:30:48 GMT\nETag: "903-591a03aa15600"\nAccept-Ranges: bytes\nContent-Length: 2307\nConnection: close\nContent-Type: text/html\n\n\r\n<!DOCTYPE html>\r\n<html lang="zh-CN">\r\n<head>\r\n <meta charset="utf-8">\r\n <title>站点创建成功-phpstudy for windows</title>\r\n <meta name="keywords" content="">\r\n <meta name="description" content="">\r\n <meta name="renderer" content="webkit">\r\n <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">\r\n <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">\r\n <meta name="apple-mobile-web-app-status-bar-style" content="black"> \r\n <meta name="apple-mobile-web-app-capable" content="yes">\r\n <meta name="format-detection" content="telephone=no">\r\n <meta HTTP-EQUIV="pragma" CONTENT="no-cache"> \r\n <meta HTTP-EQUIV="Cache-Control" CONTENT="no-store, must-revalidate"> \r\n <meta HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT"> \r\n <meta HTTP-EQUIV="expires" CONTENT="0">\r\n <style>\r\n body{\r\n font: 16px arial,\'Microsoft Yahei\',\'Hiragino Sans GB\',sans-serif;\r\n }\r\n h1{\r\n margin: 0;\r\n color:#3a87ad;\r\n font-size: 26px;\r\n }\r\n .content{\r\n width: 45%;\r\n margin: 0 auto;\r\n \r\n }\r\n .content >div{\r\n margin-top: 200px;\r\n padding: 20px;\r\n background: #d9edf7; \r\n border-radius: 12px;\r\n }\r\n .content dl{\r\n color: #2d6a88;\r\n line-height: 40px;\r\n } \r\n .content div div {\r\n padding-bottom: 20px;\r\n text-align:center;\r\n }\r\n </style>\r\n</head>\r\n<body>\r\n <div class="content">\r\n <div>\r\n <h1>站点创建成功</h1>\r\n <dl>\r\n <dt>目录说明:</dt>\r\n <dd>1:网站目录:/phpstudy安装目录/www/站点域名/</dd>\r\n <dd>2:错误提示页面:/phpstudy安装目录/www/站点域名/error/</dd>\r\n <dd>3:你可以删除或者修改该目录下的所有文件</dd>\r\n <dt>操作注意事项:</dt>\r\n <dd>1:新建站点、数据库、FTP可在phpstudy面板操作,数据库可在环境中下载数据库管理软件等;</dd>\r\n <dd>2:将网站程序放到站点目录时请使用复制,剪切可能造成程序文件权限不正确;</dd>\r\n \r\n </dl>\r\n <div>使用手册,视频教程,BUG反馈,官网地址: <a href="https://www.xp.cn" target="_blank">www.xp.cn</a> </div>\r\n \r\n </div>\r\n </div> \r\n</body>\r\n</html>', 'url': 'http://localhost/'}
请问为什么获取网页内容后 log信息会导致前后不一致呢
为了节省网络流量考虑,一般请求,只会得到头,当使用了text(),将会继续请求获取全文,所以log就是这样
text()
通过以下源码发现一个问题:
运行结果:
请问为什么获取网页内容后 log信息会导致前后不一致呢