cookiejar

Fake a cookie to scrape a site in python

拜拜、爱过 提交于 2020-01-11 07:04:09
问题 The site that I'm trying to scrape uses js to create a cookie. What I was thinking was that I can create a cookie in python and then use that cookie to scrape the site. However, I don't know any way of doing that. Does anybody have any ideas? 回答1: Please see Python httplib2 - Handling Cookies in HTTP Form Posts for an example of adding a cookie to a request. I often need to automate tasks in web based applications. I like to do this at the protocol level by simulating a real user's

Use Golang to login to private site and pull info

早过忘川 提交于 2020-01-04 09:26:50
问题 I try to use golang to login in a private area of a website and pull some info, but i don't quite seem to get it right. I manage to fetch the login page to get the csrf token, then i post the csrf token together with the login info to the login page and i login just fine. If i stop at this point, i can see the page where i am redirected. However, any subsequent calls from this point on will redirect me back to login. The code package main import ( "github.com/PuerkitoBio/goquery" "io" _ "io

How to add cookie to existing cookielib CookieJar instance in Python?

空扰寡人 提交于 2019-12-30 00:35:11
问题 I have a CookieJar that's being used with mechanize that I want to add a cookie to. How can I go about doing this? make_cookie() and set_cookie() weren't clear enough for me. br = mechanize.Browser() cj = cookielib.LWPCookieJar() br.set_cookiejar(cj) 回答1: Managed to figure this out import mechanize import cookielib br = mechanize.Browser() cj = cookielib.LWPCookieJar() br.set_cookiejar(cj) ck = cookielib.Cookie(version=0, name='Name', value='1', port=None, port_specified=False, domain='www

PHP & cURL proxy - how to make multi-user cookie jar?

倖福魔咒の 提交于 2019-12-24 04:05:18
问题 I'm developing an application that does a remote login, amongst other things, via cURL. The remote site gives out a session cookie, which I can store in my cookie jar. I want each user to my site to have a unique session on the remote site. My application works fine with just one user (me), but I'm not sure how to make it multiuser. My first thought is to set a session variable for my application users, then use this variable as the name of the cookie jar, but this seems ugly. Is there any

PHP & cURL proxy - how to make multi-user cookie jar?

半城伤御伤魂 提交于 2019-12-24 04:05:07
问题 I'm developing an application that does a remote login, amongst other things, via cURL. The remote site gives out a session cookie, which I can store in my cookie jar. I want each user to my site to have a unique session on the remote site. My application works fine with just one user (me), but I'm not sure how to make it multiuser. My first thought is to set a session variable for my application users, then use this variable as the name of the cookie jar, but this seems ugly. Is there any

Can a cookiejar object be pickled?

房东的猫 提交于 2019-12-23 13:24:10
问题 I tried pickling a CookieJar object like this: import cookielib import pickle dumpFile = open('cookie.dump','w') cj = cookielib.CookieJar() pickle.dump(cj, dumpFile) It raised the following exception: raise TypeError, "can't pickle %s objects" % base.__name__ TypeError: can't pickle lock objects Can a CookieJar be pickled? 回答1: The answer to the question as asked is "no": the jar itself is not pickle-able. However, the cookies contained in the jar, are : pickle.dump([c for c in cj], dumpFile)

python 3 Login form on webpage with urllib and cookiejar

删除回忆录丶 提交于 2019-12-21 21:25:10
问题 I've been trying to make a python script login to my reddit account but it doesnt seem to work, could anybody tell me whats wrong with my code? It runs fine it just doesnt login.¨ cj = http.cookiejar.CookieJar() opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) opener.addheaders = [('User-agent', 'Mozilla/5.0')] urllib.request.install_opener(opener) authentication_url = 'https://ssl.reddit.com/post/login' payload = { 'op': 'login', 'user_name': 'username', 'user

httplib2, how to set more than one cookie?

狂风中的少年 提交于 2019-12-09 18:18:43
问题 As you are probably aware, more often than not, an HTTP server will send more than just a session_id cookie; however, httplib2 handles cookies with a dictionary, like this: response, content = http.request(url, 'GET', headers=headers) headers = {'Cookie': response['set-cookie']} url = 'http://www.example.com/home' response, content = http.request(url, 'GET', headers=headers) So, how do I set the extra cookies? If handled with a dictionary, I can't have double Cookie keys :S. Thanks for your

Get cookie from CookieJar by name

拥有回忆 提交于 2019-12-09 02:16:10
问题 I know that I can iterate through the cookies in a cookiejar, and this would allow me to find a cookie with a particular name - but does the CookieJar object itself have any methods I can call to get a certain cookie by name? It just saves me having to write a helper method that already exists. 回答1: Yes, the __iter__ method will go through each cookie in CookieJar . for cookie in cj: print cookie.name, cookie.value, cookie.domain #etc etc A cookie is not just a name and value pair. In its

The difference between HttpCookie and Cookie?

[亡魂溺海] 提交于 2019-12-06 17:12:19
问题 So I'm confused as msdn and other tutorials tell me to use HttpCookies to add cookies via Response.Cookies.Add(cookie). But that's the problem. Response.Cookies.Add only accepts Cookies and not HttpCookies and I get this error: cannot convert from 'System.Net.CookieContainer' to 'System.Net.Cookie' Additionally, what's the difference between Response.Cookies.Add(cookie) and Request.CookieContainer.Add(cookie)? Thanks for the help in advance, I'm trying to teach myself using C#. // Cookie