Python 附加到数组并为其循环
Python append to array and for loop for it
我正在尝试将一些 link 插入到数组中然后循环它们(以输入它们)。
我的代码:
import requests
from requests_html import HTMLSession
import sys
links = []
link = "http://tvil.me"
pagedata = HTMLSession().get(link)
info = pagedata.html.find('#page-right', first=True)
sidra = info.find(".index-episode-caption")
for x in sidra:
link = x.absolute_links
links.append(link)
for i in links:
print(i)
##page = HTMLSession().get(i) - Not working because the response in bottom
##print(page.xpath("//*[contains(@id, 'change-season-')]/a"))
print(i)
的回应:
{'http://www.tvil.me/view/374/2/6/v/מסע_בזמן_Timeless.html'}
{'http://www.tvil.me/view/212/3/22/v/לוציפר_Lucifer.html'}
{'http://www.tvil.me/view/3048/1/7/v/תחנה_19_Station_19.html'}
{'http://www.tvil.me/view/3039/1/10/v/המגדלים_הגבוהים_The_Looming_Tower.html'}
{'http://www.tvil.me/view/109/5/6/v/עמק_הסיליקון_Silicon_Valley.html'}
{'http://www.tvil.me/view/68/5/11/v/ילדה_אבודה_Lost_Girl.html'}
{'http://www.tvil.me/view/556/1/20/v/שלדון_הצעיר_Young_Sheldon.html'}
{'http://www.tvil.me/view/74/4/6/v/מפרשים_שחורים_Black_Sails.html'}
{'http://www.tvil.me/view/360/2/2/v/ווסטוורלד_Westworld.html'}
[Finished in 3.7s]
它打印有 {' '} 因为它没有进入 link..
我该怎么办
你能试试这个吗?
{''}
表示它是一个 set
,您只需要 set
中的元素。 pop
给出
for x in sidra:
link = x.absolute_links.pop()
links.append(link)
您的变量 link
似乎是一个单一的元素集。所以我会推荐
link = x.absolute_links.pop()
我正在尝试将一些 link 插入到数组中然后循环它们(以输入它们)。
我的代码:
import requests
from requests_html import HTMLSession
import sys
links = []
link = "http://tvil.me"
pagedata = HTMLSession().get(link)
info = pagedata.html.find('#page-right', first=True)
sidra = info.find(".index-episode-caption")
for x in sidra:
link = x.absolute_links
links.append(link)
for i in links:
print(i)
##page = HTMLSession().get(i) - Not working because the response in bottom
##print(page.xpath("//*[contains(@id, 'change-season-')]/a"))
print(i)
的回应:
{'http://www.tvil.me/view/374/2/6/v/מסע_בזמן_Timeless.html'}
{'http://www.tvil.me/view/212/3/22/v/לוציפר_Lucifer.html'}
{'http://www.tvil.me/view/3048/1/7/v/תחנה_19_Station_19.html'}
{'http://www.tvil.me/view/3039/1/10/v/המגדלים_הגבוהים_The_Looming_Tower.html'}
{'http://www.tvil.me/view/109/5/6/v/עמק_הסיליקון_Silicon_Valley.html'}
{'http://www.tvil.me/view/68/5/11/v/ילדה_אבודה_Lost_Girl.html'}
{'http://www.tvil.me/view/556/1/20/v/שלדון_הצעיר_Young_Sheldon.html'}
{'http://www.tvil.me/view/74/4/6/v/מפרשים_שחורים_Black_Sails.html'}
{'http://www.tvil.me/view/360/2/2/v/ווסטוורלד_Westworld.html'}
[Finished in 3.7s]
它打印有 {' '} 因为它没有进入 link.. 我该怎么办
你能试试这个吗?
{''}
表示它是一个 set
,您只需要 set
中的元素。 pop
给出
for x in sidra:
link = x.absolute_links.pop()
links.append(link)
您的变量 link
似乎是一个单一的元素集。所以我会推荐
link = x.absolute_links.pop()