【问题标题】:How can I found all secure and third party cookies on any website using python selenium如何使用 python selenium 在任何网站上找到所有安全和第三方 cookie
【发布时间】:2023-02-03 02:39:42
【问题描述】:

我尝试了不同的方法来获取安全和第三方 cookie。粘贴的方法我试过了。

使用 cookiejar:

import urllib
import http.cookiejar

url = "https://www.google.com"

cookie_jar = http.cookiejar.CookieJar()
url_opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookie_jar))
url_opener.open(url)

for cookie in cookie_jar:
    print(cookie)

使用请求模块:

import requests

r = requests.get('http://www.google.com')

for cookie in r.cookies:
  print(cookie.__dict__)
  print(cookie.secure)

使用 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())

与硒:

driver = webdriver.Chrome(driver_exe, options=options,  desired_capabilities=capabilities)
driver.get('https://google.com')
cookies = driver.get_cookies()
for cookie in cookies:
   print(cookie)

任何与此相关的帮助或文档将不胜感激。

谢谢 :)

【问题讨论】:

    标签: python-3.x selenium-webdriver third-party-cookies


    【解决方案1】:

    这会给你饼干吗?

    import requests
    r = requests.get('http://www.google.com')
    print(r.cookies.get_dict())
    

    【讨论】:

      猜你喜欢
      • 2014-01-12
      • 2014-04-27
      • 2020-06-22
      • 1970-01-01
      • 1970-01-01
      • 2020-04-07
      • 1970-01-01
      • 1970-01-01
      • 2019-07-12
      相关资源
      最近更新 更多