Logging into quora using python

别来无恙 提交于 2019-12-04 14:59:52

Try something like this:

# Load proxies
proxies = []
proxies_fp = open('proxies.txt', 'r') # A list of proxies
for proxy in proxies_fp:
        proxies.append(proxy)


cookiejar = cookielib.CookieJar()

def perform_request(url, opener, credientials):
        # Instantiate our request object
        request = urllib2.Request(url)

        # Perform the request, returning a pointer to the result set.
        result = opener.urlopen(request, credentials)

        return result

credentials ={
        'username' : 'username',
        'password' : 'password'
        }

encoded_credentials = urllib.urlencode(credentials)

def main():
        # Get random proxy
        proxy = random.choice(proxies)

        # Install our proxy
        opener = urllib2.build_opener(
            urllib2.ProxyHandler({'http': proxy}),
            urllib2.HTTPRedirectHandler(),
            urllib2.HTTPHandler(debuglevel=0),
            urllib2.HTTPSHandler(debuglevel=0),
            urllib2.HTTPCookieProcessor(cookiejar),
            )
        urllib2.install_opener(opener)
        a = perform_request(url, opener, encoded_credentials)

--untested--

I've had to do something similar to this, and it worked for me this way. (Please note, that this is NOT an exact copy of code I used. I had to manipulate it a bit, and did NOT test)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!