Python CookieJar - Cookies Set By Google Analytics

883 views Asked by At

I'm a little bit confused about this situation. I'm working on a script to login into a website. I'm using CookieJar and the login method is working just fine.

If I try to display the cookieJar content:

for index, cookie in enumerate(cw.cj):
        print index, ':', cookie

I get a cookie as:

0   :   <Cookie C4CSESSID=tqb2qn92du8i9k5r4vnpd83i73 for www.example.com/>

But in my Firefox if I'm looking for that domain (in fact, w/out www) in the cookies editor, I can see also the google analytics ones (__utma, __utmc, etc).

How can I capture this cookies also in cj? My goal is to be able to modify __utmb cookie content. (I can do it from FF but I want from the script also)

Thanks

3

There are 3 answers

0
Zicu On

I'm wondering, if creating a cookieJar and adding some "mangled" cookies there (__utmb for example) it makes a difference in the next queries on that website?

Something as an overwriting for the ga cookie.

0
Reiner Gerecke On

I think you get that cookie once the tracking code on that page has executed (in the response from the Google server). As it's javascript, you'll need to find a way to either interpret Javascript in your code, or mimic the request the tracking code issues.

Interpreting Javascript out of the context of a browser could prove tricky, I suspect that the tracking code needs access to the DOM, which it probably doesn't have if you get the page with urllib for example.

2
pbacterio On

These cookies are set by the javascript code for Google Analytics. You need to interpret this code to get the cookie.

Hard work