简体   繁体   中英

How can I access 3rd party tracking parameters within a page (via Python)?

I have searched quite a bit and so far unable to determine how to access 3rd party tracking parameters within a page. With the code below I can access the cookies of the page via the python requests package, but only for the local domain, none of the 3rd party cookies/domains is returned:

import requests
# create session
s = requests.session()
# read data from a page
r = s.get('https://pythonprogramming.net/parsememcparseface/')
# show cookies and the domain that the cookies belongs to
print('>> printing cookies ...')
for cookie in s.cookies:
    print(cookie)
    print('domain=' + cookie.domain)
    print('   ck_name: ' + cookie.name)
    print('   ck_val:  ' + cookie.value)
    print('   expires: ' + str(cookie.expires))
print()    
# paramaters come back empty ...
print('>> printing parameters ...')
for param in s.params:
    print(param)

I also tried via Selenium with the Chrome driver:

import time
from selenium import webdriver
driver = webdriver.Chrome(r'{path}\chromedriver\chromedriver.exe')
driver.get('https://pythonprogramming.net/parsememcparseface/')
print('Page opened ...')
# here I can access the page HTML and local session via the driver variable
driver.quit()   # close page

but the 3rd part tracking parameters elude me. To clarify, on the page https://pythonprogramming.net/parsememcparseface/ Chomrt Dev tools show that there is a Google Analytics collector that runs and returns the parameters as per this image:

GA收集参数

Any help will be greatly appreciated! Thank you

Cookies can be read only from the domain from which they were set, that's just the way cookies work.

Google Analytics does not use data from 3rd party cookies. The only cookie it needs to function is the _ga cookie with the clientId and that is a first party cookie set by an injected javascript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM