gpt4 book ai didi

python - 如何获得第 3 方 cookie?

转载 作者:太空狗 更新时间:2023-10-30 00:07:40 27 4
gpt4 key购买 nike

我正在开发一项服务,可以监听 URL、访问每个 URL 并为每个请求获取 cookie。

目前我有这样的东西:

browser = webdriver.Firefox()
browser.get('http://google.com')
cookies = browser.get_cookies()

#parse cookies

但是,这只会给我第一方 cookie,但我还需要获得第三方 cookie。我发现 Selenium 网络驱动程序不支持这个。我想知道我怎样才能做到这一点?我不限于 Selenium,所以会感谢其他解决方案。

最佳答案

import requests
s = requests.session()
r = s.get('http://google.com')
r = s.get('http://facebook.net')
for cookie in s.cookies:
print(cookie)

http://python-requests.org/


使用:Selenium + PhantomJS

from selenium import webdriver

cookie_file_path = 'cookie.txt'

args = ['--cookies-file={}'.format(cookie_file_path)]
driver = webdriver.PhantomJS(service_args=args)
driver.get('http://google.com')
driver.get('http://facebook.com')
with open(cookie_file_path) as f:
print(f.read())

输出(包装):

[General]
cookies="@Variant(\0\0\0\x7f\0\0\0\x16QList<QNetworkCookie>\0\0\0\0\x1\0\0\0\a\0
\0\0\xd6NID=67=SZetUV-oLq_M8ik40VT2GEIb45LMaXkhm6H3zx1wULO52qkCHPc9AML_p5eubW4zL
Ms158YAYKQTdCJzb4mInix_Zek6P8Ej1XZh9h5Ng3I7X4gZuE_S-Fl2YpaSYd9B; HttpOnly; expir
es=Wed, 18-Dec-2013 02:44:31 GMT; domain=.google.co.kr; path=/\0\0\0ldatr=kMm_Ue
0P06lxFANs8c-wCgwG; HttpOnly; expires=Thu, 18-Jun-2015 02:44:32 GMT; domain=.fac
ebook.com; path=/\0\0\0Kreg_fb_gate=https%3A%2F%2Fwww.facebook.com%2F; domain=.f
acebook.com; path=/\0\0\0Jreg_fb_ref=https%3A%2F%2Fwww.facebook.com%2F; domain=.
facebook.com; path=/\0\0\0\xa2PREF=ID=be651672f1ddac52:U=515e3545a8a53080:FF=0:T
M=1371523471:LM=1371524047:S=iqfF3qNRUwVsInZR; expires=Thu, 18-Jun-2015 02:54:07
GMT; domain=.google.com; path=/\0\0\0\xd4NID=67=pm8Ws9703eugHhhImX_hBpqhUyAhCUG
TebjDZ6YY_cP7CuvIA4x8ElgGaj6tOweXFxxjALoX1PwqFvHHkUY1kerw3vwM-VaIyyPVSADMqOnR-Ty
ed_bGU3bk6YSwUUeG; HttpOnly; expires=Wed, 18-Dec-2013 02:54:07 GMT; domain=.goog
le.com; path=/\0\0\0\xa9PREF=ID=9769c9a2d96728cf:U=3d59c2548337b74e:FF=0:NW=1:TM
=1371523471:LM=1371524047:S=vE5Y_06LhP4unse7; expires=Thu, 18-Jun-2015 02:54:07
GMT; domain=.google.co.kr; path=/)"

关于python - 如何获得第 3 方 cookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17146514/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com