1.python
urllib.urlencode(params)post
換成學習
urllib.parse.urlencode(params)url
2.code
在python3.3後urllib2已經不能再用,只能用urllib.request來代替
import urllib.request
print(urllib.request.__file__)
3.教程
在學習爬蟲的時候,用到postdata時,遇到了一個問題:it
POST data should be bytes or an iterable of bytesclass
一開始覺得是本身代碼寫的有問題,對照着教程和本身的代碼,又沒有錯誤。import
在網上查了一下,能夠用下面的一個語句解決。module
data = urllib.parse.urlencode(values).encode(encoding='UTF8')