Curl代码到python转换
如果代码类似于:Curl代码到python转换,python,cookies,python-3.x,session-cookies,Python,Cookies,Python 3.x,Session Cookies,如果代码类似于: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_COOKIESESSION, 1); curl_setopt($ch,
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_COOKIE, 'id='.$id);
$result = curl_exec($ch);
因为这个不适合我
id="j4156f9150ece727e38bbf982634ee"
cookie = {'id': id}
content = requests.post(url, cookies=cookie)
print(id)
print(cookie)
print(content.url)
print(content.cookies)
结果是:
['j4156f9150ece727e38bbf982634ee']
{'id': 'j4156f9150ece727e38bbf982634ee'}
http://example.com
<<class 'requests.cookies.RequestsCookieJar'>[]>
['j4156f9150ece727e38bbf982634ee']
{'id':'j4156f9150ece727e38bbf982634ee'}
http://example.com
什么意思?>>导入请求
>>> import requests
>>> id="j4156f9150ece727e38bbf982634ee"
>>> cookie = {'id': id}
>>> content = requests.post('http://www.google.com',cookies=cookie)
>>> print id
j4156f9150ece727e38bbf982634ee
>>> print cookie
{'id': 'j4156f9150ece727e38bbf982634ee'}
>>> print content.url
http://www.google.com/
>>> print content.cookies
<<class 'requests.cookies.RequestsCookieJar'>[<Cookie id=j4156f9150ece727e38bbf982634ee for />]>
>>> print content.cookies.get('id')
j4156f9150ece727e38bbf982634ee
>>>id=“j4156f9150ece727e38bbf982634ee”
>>>cookie={'id':id}
>>>content=requests.post('http://www.google.com,cookies=cookie)
>>>打印id
j4156f9150ece727e38bbf982634ee
>>>打印cookie
{'id':'j4156f9150ece727e38bbf982634ee'}
>>>打印content.url
http://www.google.com/
>>>打印内容.cookies
>>>打印content.cookies.get('id')
j4156f9150ece727e38bbf982634ee