Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
拆下b&x27;Python3中的from值_Python - Fatal编程技术网

拆下b&x27;Python3中的from值

拆下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(

正在尝试从输出中删除“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)
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))