HW2 <<
Previous Next >> HW2之2
HW2之1
設計一甲
import urllib.request
url = "https://nfulist.herokuapp.com/?semester=1091&courseno=0762"
cp1a = []
for line in urllib.request.urlopen(url):
cp1a.append(int(line.decode('utf-8').rstrip()))
print(cp1a)
print("總共有" + str(len(cp1a)) + " 筆")
total = len(cp1a)
for i in range(total):
print("http://github.com/" + str(cp1a[i]) + "/cp2020")
1. import urllib.request
導入 urllib.request: https://docs.python.org/3/library/urllib.request.html
並且透過urllib.request 模組中的 urlopen() 開啟網路 url 連結資料
2. url = "https://nfulist.herokuapp.com/?semester=1091&courseno=0762"
設定名單的源頭從https://nfulist.herokuapp.com/?semester=1091&courseno=0762這個網址來
3.cp1a = []
設定cp1a這個數列
4. for line in urllib.request.urlopen(url):
cp1a.append(int(line.decode('utf-8').rstrip()))
透過 urllib.request模組裡的urlopen()取下網際資料但由於資料為binary格式所以必須使用utf-8進行 編碼將它轉換成我們可看得懂的數字
5. print(cp1a)
顯示cp1a , 由於前面有定義數列了所以cp1a的資料將以數列方式呈現
6. print("總共有" + str(len(cp1a)) + " 筆")
顯示 總共有+字串cp1a的資料數+筆
7. total = len(cp1a)
設定total為cp1a資料數
8. for i in range(total):
print("http://github.com/" + str(cp1a[i]) + "/cp2020")
用迴圈下去跑(total的資料數)相同的次數
並顯示http://github.com/+ cp1a資料裡每個數據 + /cp2020

HW2 <<
Previous Next >> HW2之2