获取到了67个列表页,但是每个列表页没法单独取出来?

for page in range(1, 67):
    url_list = 'http://top.chinaz.com/hangye/index_news_{}.html'.format(page) #获取列表页链接
    # url_list1 = url_list.split()
    print(type(url_list))
    print(url_list)

输出结果:

<class 'str'>
http://top.chinaz.com/hangye/index_news_1.html
<class 'str'>
http://top.chinaz.com/hangye/index_news_2.html
<class 'str'>
http://top.chinaz.com/hangye/index_news_3.html
<class 'str'>
http://top.chinaz.com/hangye/index_news_4.html
...
<class 'str'>
http://top.chinaz.com/hangye/index_news_67.html

我把获取到的链接,都赋给了url_list。
打印一下url_list的内容和类型。
请问,怎么从url_list里把每一个链接单独取出来?因为我后面需要把每个链接都单独打开。

阅读 1.7k
2 个回答

听不懂你在说什么.

保存到数组就行了.

url_list = ['http://top.chinaz.com/hangye/index_news_{}.html'.format(page) for page in range(1, 67)]  
urls = []
for page in range(1, 67):
    # 获取列表页链接
    url = 'http://top.chinaz.com/hangye/index_news_{}.html'.format(page) 
    urls.append(url)
 print(type(urls))
 print(urls)

先多熟悉下python基本数据结构的用法。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题