curl和urllib2 python有什么区别

时间:2015-07-22 05:44:45

标签: python curl urllib2

我正在尝试从Google-play获取信息

使用:

url = 'https://play.google.com/store/geteviews'
data = 'reviewType=0&pageNum=2&id=com.mobile.jets&reviewSortOrder=1&xhr=1'

案例1: 我在终端

中使用curl或wget
curl --verbose --data "reviewType=0&pageNum=4&id=com.mobile.jets&reviewSortOrder=1&xhr=1" "https://play.google.com/store/getreviews"

结果:

* About to connect() to play.google.com port 443 (#0)
*   Trying 173.194.72.101...
* connected
* Connected to play.google.com (173.194.72.101) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using ECDHE-RSA-AES128-GCM-SHA256
* Server certificate:
*    subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.google.com
*    start date: 2015-07-01 20:58:15 GMT
*    expire date: 2015-09-29 00:00:00 GMT
*    subjectAltName: play.google.com matched
*    issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
*    SSL certificate verify ok.
> POST /store/getreviews HTTP/1.1
> User-Agent: curl/7.26.0
> Host: play.google.com
> Accept: */*
> Content-Length: 65
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 65 out of 65 bytes
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=UTF-8
< Content-Disposition: attachment; filename="response.txt"
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: Fri, 01 Jan 1990 00:00:00 GMT
< Date: Wed, 22 Jul 2015 05:09:29 GMT
< P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< Server: GSE
< Set-Cookie: PLAY_PREFS=ChYIABISCgJWThCWv6qh6ykolr-qoesp:S:ANO1ljJeDa0ijDsbjg; Path=/; Secure; HttpOnly
< Set-Cookie: NID=69=ckMvpyKSdPrv7pPS-DBTZfXH8gJBrQVBqlZka-gBtZ2_4Mx1pvEIlHl9LEBq68mfDPa-1Civ0TB70ubpkdZ5Eci5h802GraBa_PU8NMohrZ5__NDpEcZbNjTWmY-Ntib;Domain=.google.com;Path=/;Expires=Thu, 21-Jan-2016 05:09:29 GMT;HttpOnly
< Alternate-Protocol: 443:quic,p=1
< Accept-Ranges: none
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
< 
)]}'

[["ecr",2,"multiple data...",4]]

案例2: 我在python中使用urllib2

import urllib2

url = 'https://play.google.com/store/geteviews'
data = 'reviewType=0&pageNum=2&id=com.mobile.jets&reviewSortOrder=1&xhr=1'

response = urllib2.urlopen(url, data)
print response.info()
print response.read()

结果:

Content-Type: application/json; charset=UTF-8
Content-Disposition: attachment; filename="response.txt"
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Wed, 22 Jul 2015 05:32:58 GMT
P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Set-Cookie: NID=69=Asjf_t7A7xKaUh9AZKi4g6pw23AjKzbYrZrYs7itgIhvFzmrVxjdLeKIx5CFgJ37VpxqlS-24jQIi0-c0K56UB8PpZZq2bMRhrlVvWzf562ZDvD53Hx09MG7ZLiSn5ho;Domain=.google.com;Path=/;Expires=Thu, 21-Jan-2016 05:32:58 GMT;HttpOnly
Alternate-Protocol: 443:quic,p=1
Accept-Ranges: none
Vary: Accept-Encoding
Connection: close

)]}'

[["ger",1]
]
[Finished in 0.3s]

为什么呢? curl和urllib2 python之间有什么区别?

1 个答案:

答案 0 :(得分:1)

区别在于你拼错了网址

url = 'https://play.google.com/store/geteviews'

应该是

url = 'https://play.google.com/store/getreviews'