我是Python的新手,似乎遇到了問題。我試圖來urlencode用戶代理字符串...正確地對用戶代理進行網址編碼
import urllib
UserAgent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3 Gecko/2008092417 Firefox/3.0.3'
print 'Agent: ' + UserAgent
print urllib.urlencode(UserAgent)
導致...
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3 Gecko/2008092417 Firefox/3.0.3
Traceback (most recent call last):
File "D:\Source\SomePath\test.py", line 7, in <module>
print urllib.urlencode(UserAgent)
File "C:\Python26\lib\urllib.py", line 1254, in urlencode
raise TypeError
TypeError: not a valid non-string sequence or mapping object
Press any key to continue . . .
我只能假設,雖然UserAgent
被正確打印,我要麼錯過了關於urllib.urlencode()
的一些字符串轉義選項或根本性錯誤?
該死的,我知道它一定是簡單的。謝謝 – Basic