在python中遍历网址列表

时间:2018-07-10 06:36:58

标签: python python-3.x urllib

我是python的新手,我在数组中有url列表,并且是迭代列表,但我遇到了错误

  

urllib.error.HTTPError:HTTP错误404:未找到

在获取网址时。在线code Editor here上我做错了。谢谢

import numpy as np
import urllib.request


lists = ["https://prod-video-eu-central-1.pscp.tv/Kxf6yJwqKtM611tEBKt0kPlPMKdDsrPZDhjluIPeiCz0XsSq-utkVn2kQk2JdaH3rdLCQc3lqjfnmHZtxa-Xzw/live_thumbnail/eu-central-1/eyJkIjowfQ/latest.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsInZlcnNpb24iOiIyIn0.eyJBbGxvd2VkUHJvdG9jb2xzIjpbInRodW1iIl0sIkJyb2FkY2FzdElkIjoiMW1ueGVvRHJlVm9HWCIsIkdyYW50VHlwZSI6InJlYWQiLCJHcmFudGVkQXQiOjE1MzExNDM3MzksIkdyYW50ZWRUbyI6IndlYi1yYXRlLWxpbWl0ZWQtNWM5MmJjNmNhZGJiNjdmZjcxZGViMmQzNGQ2NWNjMmYiLCJTdHJlYW1OYW1lIjoiS3hmNnlKd3FLdE02MTF0RUJLdDBrUGxQTUtkRHNyUFpEaGpsdUlQZWlDejBYc1NxLXV0a1ZuMmtRazJKZGFIM3JkTENRYzNscWpmbm1IWnR4YS1YenciLCJleHAiOjE1MzEzMTY1Mzl9.4zU4iPPcrG1pXAl3zNu4Yn1GatUl2kJtja33Zbkpkjk&service=proxsee&digest=7I3s5DHm3nr5QEyw2OM5wvmoP3bUdmrE9ffn5WHZ_a0&ts=765571869",
         "https://prod-video-eu-central-1.pscp.tv/Kxf6yJwqKtM611tEBKt0kPlPMKdDsrPZDhjluIPeiCz0XsSq-utkVn2kQk2JdaH3rdLCQc3lqjfnmHZtxa-Xzw/live_thumbnail/eu-central-1/eyJkIjowfQ/latest.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsInZlcnNpb24iOiIyIn0.eyJBbGxvd2VkUHJvdG9jb2xzIjpbInRodW1iIl0sIkJyb2FkY2FzdElkIjoiMW1ueGVvRHJlVm9HWCIsIkdyYW50VHlwZSI6InJlYWQiLCJHcmFudGVkQXQiOjE1MzExNDM3MzksIkdyYW50ZWRUbyI6IndlYi1yYXRlLWxpbWl0ZWQtNWM5MmJjNmNhZGJiNjdmZjcxZGViMmQzNGQ2NWNjMmYiLCJTdHJlYW1OYW1lIjoiS3hmNnlKd3FLdE02MTF0RUJLdDBrUGxQTUtkRHNyUFpEaGpsdUlQZWlDejBYc1NxLXV0a1ZuMmtRazJKZGFIM3JkTENRYzNscWpmbm1IWnR4YS1YenciLCJleHAiOjE1MzEzMTY1Mzl9.4zU4iPPcrG1pXAl3zNu4Yn1GatUl2kJtja33Zbkpkjk&service=proxsee&digest=7I3s5DHm3nr5QEyw2OM5wvmoP3bUdmrE9ffn5WHZ_a0&ts=765571869"]
for index,value in enumerate(lists):
    urllib.request.urlopen(value)

1 个答案:

答案 0 :(得分:1)

Checking您提供的URL的 HTTP状态代码,我得到:

Response: 404 Not Found for your URL https://i.ytimg.com/vi/y4vD9LM2z3k/hqdefault_live.jpg

因此,您的第三个链接不起作用,当请求使用urllib打开它时,它将返回404错误。 另外两个链接有效,您没有问题,仅使用它们时程序也不应该返回任何错误。

P.S .:为什么可以使用enumerate

for link in lists: 
    urllib.request.urlopen(link)