cookieHelper

function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
//获取cookie
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1);
if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
}
return "";
}
//清除cookie
function clearCookie(name) {
setCookie(name, "", -1);
}

转载于:https://www.cnblogs.com/lee2011/p/4837703.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码主要是使用 Selenium 和 DevTools 来获取网络请求的相关信息。下面是 Python 代码的转换: ```python from selenium.webdriver import Chrome from selenium.webdriver.chrome.service import Service from msedge.selenium_tools import Edge, EdgeOptions from selenium.webdriver.common.desired_capabilities import DesiredCapabilities # 创建 Chrome 浏览器实例 caps = DesiredCapabilities.CHROME.copy() caps['goog:loggingPrefs'] = {'performance': 'ALL'} service = Service('/path/to/chromedriver') driver = Chrome(service=service, desired_capabilities=caps) # 创建 Edge 浏览器实例 caps = DesiredCapabilities.EDGE.copy() caps['goog:loggingPrefs'] = {'performance': 'ALL'} options = EdgeOptions() options.use_chromium = True driver = Edge(options=options, desired_capabilities=caps) # 获取 DevToolsSession devTools = driver session = devTools.get_devtools_session() # 启用 Network,并监听 DevToolsEventReceived 事件 session.domains['Network'].enable_network() LIST_DevToolsSession = [] # 定义一个列表用于存储 DevToolsSession def on_event_received(sender, e): global LIST_DevToolsSession LIST_DevToolsSession.append({ 'EventName': e.EventName, 'body': e.EventData }) session.devtools_event_received += on_event_received # 获取 DevToolsSession_实体 _session = next((s for s in LIST_DevToolsSession if s['Session']['是验证']), None) if _session: 目标会话 = next((s for s in LIST_DevToolsSession if s['Session']['requestId'] == _session['Session']['requestId'] and s['EventName'] == 'ResponseReceivedExtraInfo'), None) if 目标会话: 后置令牌_未处理 = 目标会话['Session']['headers']['set-cookie'] # .Replace("\n", ";"); 后置令牌 = CookieHelper.GetCookieStrByHeader换行(后置令牌_未处理) if 后置令牌: driver.quit() ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值