我正在尝试将一些链接插入到数组中,然后使用for循环(以便输入它们)。
我的代码:
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"))
< p > 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]
它打印了{' '}, 因为它没有进入链接...我该怎么办?
{}
表示这是一个set
。所以你有一个可迭代对象的列表... 如果你执行for i in links: for j in i: print(j)
就可以工作了。 - rafaelc