def User_Agent(): txt = open('Pc-ua.txt', 'rb') data = txt.read().decode('utf-8') # python3一定要加上這句不然會編碼報錯! txt.close() # 獲取txt的總行數! n = data.count('\n') #print("總行數", n) # 選取隨機的數 i = random.randint(1, (n + 1)) #print("本次使用的行數", i) ###得到對應的i行的數據 line=linecache.getline(r'Pc-ua.txt', i) print(line) return line