拆下b&x27;Python3中的from值
正在尝试从输出中删除“b”拆下b&x27;Python3中的from值,python,Python,正在尝试从输出中删除“b” word_site = "http://link.de/prox.txt" response = requests.get(word_site) WORDS = response.content.splitlines() print (random.choice(WORDS)) Prints b'116.11.254.37:80' 当我尝试 word_site = "http://link.de/prox.txt" response = requests.get(
word_site = "http://link.de/prox.txt"
response = requests.get(word_site)
WORDS = response.content.splitlines()
print (random.choice(WORDS))
Prints b'116.11.254.37:80'
当我尝试
word_site = "http://link.de/prox.txt"
response = requests.get(word_site)
WORDS = response.content.splitlines()
print (WORDS.decode('utf-8'))
print (random.choice(WORDS))
输出为:
print (WORDS.decode('utf-8'))
AttributeError: 'list' object has no attribute 'decode'
我做错了什么?.txt链接只包含代理行。splitlines返回一个列表,您必须对列表中的每个元素进行操作
word_site = "http://link.de/prox.txt"
response = requests.get(word_site)
WORDS = response.content.splitlines()
utf8_words = [w.decode('utf-8') for w in WORDS]
print (utf8_words)
print (random.choice(utf8_words))
更好的是(来自megalng):
word_site = "http://link.de/prox.txt"
response = requests.get(word_site)
WORDS = response.content.decode('utf-8').splitlines()
print (WORDS)
print (random.choice(WORDS))