with open('IP.txt', 'r', encoding="utf-8") as f:#打开IP的地址 读取 txt = f.read() return random.choice(txt.split('\n')) #反馈合成列表 随即选择一个 ’'' 例如: IP.txt 里的内容 随即提取每一行 182.92.242.11:80 58.52.201.117:8080 175.43.156.60:9999 47.110.59.21:8080 175.43.34.49:9999 1.198.72.164:9999 222.190.110.167:808 使用txt.split('\n') 后成这样 ['182.92.242.11:80', '58.52.201.117:8080', '175.43.156.60:9999', '47.110.59.21:8080', '175.43.34.49:9999', '1.198.72.164:9999', '222.190.110.167:808'] '''