0

如果 curl 代码如下:

$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'>[]>

什么意思?

4

1 回答 1

0
>>> 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
于 2013-10-13T13:09:23.930 回答