当前位置: 首页 > news >正文

农村服务建设有限公司网站横沥做网站

农村服务建设有限公司网站,横沥做网站,网站建设银行北京冬奥会纪念币发行时间,湖北建设执业注册中心网站selenium的官方不提供获取状态码#xff0c;Conten-Type#xff0c;以及重定向路径的方法#xff0c;并且官方说这些功能将来也不会有。java - How to get HTTP Response Code using Selenium WebDriver - Stack Overflow 非官方的方法大概有下面几种 1.通过requests重新请…selenium的官方不提供获取状态码Conten-Type以及重定向路径的方法并且官方说这些功能将来也不会有。java - How to get HTTP Response Code using Selenium WebDriver - Stack Overflow 非官方的方法大概有下面几种 1.通过requests重新请求一遍url获取response里面的状态码 2.通过中间代理服务器来获取比如selenium-wireselenium-wire里面内建了一个代理服务器通过代理服务器可以获取各个请求的状态码 3.通过分析chrome的performance log来获取状态码以及重定向路径 1的方法会多访问一遍网络并且不能支持mata或js的重定向。2的方法只访问一次网络但同样不能支持mata或js的重定向只有3的方法只访问一次网络可以获取所有的状态。 并且1的方法在python环境上打开一些https网站还有如下bug ssl.SSLError: [SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1131) · Issue #2653 · urllib3/urllib3 · GitHuby 这个问题的原因是This error comes up when using OpenSSL 3 to connect to a server which does not support it. The solution is to downgrade the cryptography package in python: python - SSL error unsafe legacy renegotiation disabled - Stack Overflow 要么修改openssl.cnf要么降级cryptography要么设置ctx根据我测试的结果只有修改cnf才能彻底解决最简单的方法是在cnf后面加上Options UnsafeLegacyRenegotiation 如果使用docker应该写成这样 RUN echo Options UnsafeLegacyRenegotiation /usr/lib/ssl/openssl.cnf 如何通过performance log来获取状态 performanceLog.py import jsondef getHeader(headers,header):for key,value in headers.items():if key.lower()header:return valuereturn def getRedirectPath(driver):redirctPath[]requestDic{}frameIdNonefor entry_json in driver.get_log(performance):entry json.loads(entry_json[message])# print(entry)if entry[message][method] Network.requestWillBeSent:if entry[message][params][loaderId]entry[message][params][requestId] and (frameId is None or frameIdentry[message][params][frameId]):# print(entry)if frameId is None:frameIdentry[message][params][frameId]if entry[message][params][redirectHasExtraInfo]:# 设置重定向前的状态itemredirctPath[len(redirctPath)-1]item[status]entry[message][params][redirectResponse][status]item[reason]locationitem[contentType]getHeader(entry[message][params][redirectResponse][headers],content-type)item{url:entry[message][params][request][url],status:,reason:,contentType:}requestDic[entry[message][params][requestId]]itemredirctPath.append(item)elif entry[message][method] Network.responseReceived and entry[message][params][requestId] in requestDic:# print(entry)itemrequestDic[entry[message][params][requestId]]item[status]entry[message][params][response][status]item[contentType]getHeader(entry[message][params][response][headers],content-type)elif entry[message][method] Page.frameRequestedNavigation and frameIdentry[message][params][frameId]:# print(entry)# 设置重定向前的状态itemredirctPath[len(redirctPath)-1]item[reason]entry[message][params][reason]return redirctPath后来发现一些网站不能获取contentType,原因是header需要忽略大小写修改了一下代码。当然你自己修改代码后可以获取任何你需要的header。 各个事件的顺序大致如下 Page.frameStartedLoading Network.requestWillBeSent Network.responseReceived Network.dataReceived Page.frameNavigated Network.requestServedFromCache Network.loadingFinished Network.resourceChangedPriority Page.domContentEventFired Network.loadingFailed Page.loadEventFired Page.frameStoppedLoading 注释Page.frameScheduledNavigation已经被废弃改成Page.frameRequestedNavigation 官方对performance log的文档很少在网上也没有找到类似的讨论上面的代码完全是我根据数据分析出来的目前看来是对的如果不对请告诉我。  Chrome DevTools Protocol - version 1-2 - Page domain 测试代码 from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities import time from performanceLog import getRedirectPathcaps DesiredCapabilities.CHROME caps[goog:loggingPrefs] {performance: ALL} options webdriver.ChromeOptions() # 必须是headlessnew否则download.default_directory不起作用 options.add_argument(--headlessnew) # 下面这些参数是必须的否则可能出错 options.add_argument(--disable-gpu) options.add_argument(--no-sandbox) options.add_argument(--disable-dev-shm-usage)driver webdriver.Chrome(optionsoptions,desired_capabilitiescaps)driver.get(http://localhost/redirect) # 必须等待几秒钟否则metaTagRefresh不起作用 time.sleep(3)print(getRedirectPath(driver)) driver.quit() 输出结果 [{     url: http://localhost/redirect,     status: 302,     reason: location,     contentType: text/html; charsetutf-8 }, {     url: http://localhost/static/index3.html,     status: 200,     reason: scriptInitiated,     contentType: text/html }, {     url: http://localhost/static/redirect.html,     status: 200,     reason: metaTagRefresh,     contentType: text/html }, {     url: http://localhost/,     status: 200,     reason: ,     contentType: text/html; charsetutf-8 }] 可以看出这里面有3种不同类型的重定向location的通常的重定向后面2种用requests或者代理都无法获取。 locationresponse header里面的location重定向 scriptInitiatedjs重定向 metaTagRefreshmeta tag重定向
http://www.ho-use.cn/article/10819037.html

相关文章:

  • 企业做的网站推广方案的步骤北京小程序开发平台
  • 机械网站案例丽水做企业网站的公司
  • 怎么开免费网站DW怎么做网站下拉菜单
  • 富阳网站建设公司wordpress 个人网站
  • 甘肃省建设厅网站连云港抖音优化
  • 个体工商户经营范围网站开发logo制作步骤
  • 厦门做网站排名wordpress没有加载图片
  • 如何搭建网站的支付接口个人网站可以做淘客
  • 商城网站怎样做自己做网站要学前端和后端
  • c语言做项目网站互联网黄页是什么
  • 设计网站推荐素材网站广州网站建设制作的公司
  • 云微助力网站建设安溪县建设局网站
  • 怎么在自己的网站上做漂浮链接网站建设一般用哪种语言开发
  • wordpress主题样式表温州优化推广
  • 做彩票网站需要什么条件自己随便玩玩的网站怎么建设
  • 网站接入激励视频广告在网站建设工作会议上讲话
  • 南阳网站建设制作价格网站域名设计找谁
  • 那些网站可以做团购你们交学费做网站
  • 温州网站建设方案wordpress视差插件
  • 深圳专业做网站开发费用怎么做下载类的网站吗
  • 潍坊建站模板搭建设计logo网站赚钱
  • 母婴类网站 网站建设方案书 备案找工程承包app
  • 星乐seo网站关键词排名优化网页版梦幻西游奔波儿灞
  • 手机看网站wordpress安装到网站
  • 建设个人网站需要备案吗百度搜索优化关键词排名
  • 天河网站 建设seo信科分公司装修网站有哪些
  • 最专业的营销网站建设中国万网怎么自己做网站
  • 南头专业企业网站建设公司wordpress 3.3.2
  • 我先做个网站怎么做的网站安全怎么做
  • 网站推荐入口wordpress媒体库创建文件夹