Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python append to array and for loop for it

I am trying to insert to array some links then for loop them ( to enter them).

My code :

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"))

The response of 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]

Its printed with {' '} because this its not entering the link.. What should I do.

like image 855
kaki Avatar asked May 02 '26 07:05

kaki


1 Answers

Can you try this?

{''} means its a set and you only want the element in the set. And pop gives that

for x in sidra:
    link = x.absolute_links.pop()
    links.append(link)
like image 80
Nannan AV Avatar answered May 03 '26 20:05

Nannan AV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!