如何手动将更多cookie添加到已在机械化中设置cookie的会话中?

如何手动将更多cookie添加到已在机械化中设置cookie的会话中?,第1张

概述我有一个 python脚本,它抓取一个页面并收到一个cookie.我想将另一个cookie附加到正在发送到服务器的现有cookie中.因此,在下一个请求中,我从原始页面加上我手动设置的cookie. 无论如何这样做?我在机械化中尝试了添加标题,但它被忽略了. 使用set_cookie方法: >>> import mechanize>>> br=mechanize.Browser()>>> b 我有一个 python脚本,它抓取一个页面并收到一个cookie.我想将另一个cookie附加到正在发送到服务器的现有cookie中.因此,在下一个请求中,我从原始页面加上我手动设置的cookie.

无论如何这样做?我在机械化中尝试了添加标题,但它被忽略了.

解决方法 使用set_cookie方法:

>>> import mechanize>>> br=mechanize.browser()>>> br.set_cookie?DeFinition: br.set_cookie(self,cookie_string)Docstring:    Request to set a cookie.    Note that it is NOT necessary to call this method under ordinary    circumstances: cookie handling is normally entirely automatic.  The    intended use case is rather to simulate the setting of a cookie by    clIEnt script in a web page (e.g. JavaScript).  In that case,use of    this method is necessary because mechanize currently does not support    JavaScript,VBScript,etc.    The cookie is added in the same way as if it had arrived with the    current response,as a result of the current request.  This means that,for example,if it is not appropriate to set the cookie based on the    current request,no cookie will be set.    The cookie will be returned automatically with subsequent responses    made by the browser instance whenever that's appropriate.    cookie_string should be a valID value of the Set-cookie header.    For example:    browser.set_cookie(        "sID=abcdef; expires=Wednesday,09-Nov-06 23:12:40 GMT")    Currently,this method does not allow for adding RFC 2986 cookies.    This limitation will be lifted if anybody requests it.
总结

以上是内存溢出为你收集整理的如何手动将更多cookie添加到已在机械化中设置cookie的会话中?全部内容,希望文章能够帮你解决如何手动将更多cookie添加到已在机械化中设置cookie的会话中?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1078414.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存