在pycurl中登录并使用cookie [英] Logging in and using cookies in pycurl

查看:410
本文介绍了在pycurl中登录并使用cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要下载受密码保护的网页上的档案。要手动访问页面,我首先必须通过普通登录页面进行身份验证。我想使用curl在脚本中获取此页面。

我的脚本首次登录。它似乎成功 - 它从一个PUT返回一个200到/登录。但是,所需页面的抓取失败,有500个。

I need to download a file that is on a password protected page. To get to the page manually I first have to authenticate via an ordinary login page. I want to use curl to fetch this page in script.
My script first logins. It appears to succeed--it returns a 200 from a PUT to /login. However, the fetch of the desired page fails, with a 500.

我使用的是cookie jar:

I am using a "cookie jar":

C.setopt(pycurl.COOKIEJAR, 'cookie.txt')

在详细模式下,我可以看到当我获取我需要的文件时交换的Cookie。现在我的问题:有没有更多使用COOKIEJAR?

In verbose mode, I can see cookies being exchanged when I fetch the file I need. Now my question: Is there more to using a COOKIEJAR?

推荐答案

我相信Curl会存储cookie,明确。我只用过这个命令行界面。扫描文档我想你可能想尝试:

I believe Curl will store the cookies but you need to use them explicitly. I've only ever used the command line interface for this though. Scanning the documentation I think you might want to try:

C.setopt(pycurl.COOKIEFILE, 'cookie.txt')

(第二次请求前)

这篇关于在pycurl中登录并使用cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆