我想從選擇列表中選擇一個隨機的URL,但它不工作。這裏是我的代碼:Python的隨機URL選擇
import urllib, urllib2, sys
num = sys.argv[1]
print 'Started'
phones = [
'http://1.1.1.6/index.htm,'
'http://1.1.1.5/index.htm,'
'http://1.1.1.4/index.htm,'
'http://1.1.1.3/index.htm,'
'http://1.1.1.2/index.htm,'
'http://1.1.1.1/index.htm'
]
from random import choice
data = urllib.urlencode({"NUMBER":num, "DIAL":"Dial", "active_line":1})
while 1:
for phone in phones:
urllib2.urlopen(choice(phone),data) # make call
urllib2.urlopen(choice(phone)+"?dialeddel=0") # clear
logs
這是錯誤我得到
File "p.py", line 21, in ?
urllib2.urlopen(choice(phone),data) # make call
File "/usr/lib64/python2.4/urllib2.py", line 130, in urlopen
return _opener.open(url, data)
File "/usr/lib64/python2.4/urllib2.py", line 350, in open
protocol = req.get_type()
File "/usr/lib64/python2.4/urllib2.py", line 233, in get_type
raise ValueError, "unknown url type: %s" % self.__original
ValueError: unknown url type: 5
任何幫助表示讚賞。謝謝!
選擇(「你好」) - >一個字母...選項(電話)將只返回URL –