1
這是我用來從多個URL中提取數據的代碼。 不幸的是,我無法讓它適用於列表中的多個URL。Python 2.7從json api的多個URL中提取數據
有什麼想法?
import urllib
import re
urls = ("http://pool.webcoin.us/plt/index.php/?page=api&action=getpoolstatus&api_key=0c57173da8c900831fc111003ea636d5c261e79e76b670f3b51a2d325f9b94db",
"http://uno.coin-pool.org/index.php?page=api&action=getpoolstatus&api_key=f20daa5ea5945c1b9641b81d8dd9f4b556153182c03a2a2a94d7a95abc6dc4f8",
"http://goat.easy-mining.net/index.php?page=api&action=getpoolstatus&api_key=5d232e86cd1a0cdfdafdcb0722da48c21778d35cd8654f7dbc82202881163df9")
for url in urls:
source = urllib.urlopen(url)
regexp = r">(\d+(?:\.\d*)?)<"
found = 0
for line in source.readlines():
if found:
match = re.search(regexp,line)
break
if "networkdiff" in line:
found = 1
print match.groups()
那麼爲什麼不嘗試**循環**並分別加載每個網址?是什麼讓你認爲'urllib.urlopen()'會支持列表參數? –