簡體   English   中英

curl和urllib2 python有什么區別

[英]what is difference between curl and urllib2 python

我正在嘗試從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有什么區別?

區別在於您拼錯了網址

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

應該

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM