2013-10-13 75 views
0

怎麼會看的代碼與請求蟒蛇,如果捲曲的代碼,如:捲曲代碼到Python轉換

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

這是什麼意思?

回答

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