5

I am trying to check if link contains http and print the URL.

import requests
from requests_html import HTMLSession
import sys

link = "http://www.tvil.me/view/93/4/8/v/%D7%90%D7%99%D7%99_%D7%96%D7%95%D7%9E%D7%91%D7%99_IZombie.html"
enter_episodes = HTMLSession().get(link)
page = enter_episodes.html
s = page.xpath("//*[@class='view-watch-button']/a")
for l in s:
    link = l.links
    if link != "set()":
        print(link)

Response:

{'http://streamcloud.eu/ga4m4hizbrfb/iZombie.S04E08.HDTV.x264-SVA.mkv.html'}
{'http://uptostream.com/77p26f7twwhe'}
set()
{'https://clipwatching.com/aog2ni06rzjt/rrFhepnbFfpt6xg.mkv.html'}
set()
[Finished in 1.7s]

I tried to delete the set() response and to get only the link without {' and '}.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
kaki
  • 103
  • 2
  • 9
  • use `pop()` in a set to get the full result; And you must print `set()` somewhere else –  May 04 '18 at 00:39

1 Answers1

0

You just need to make sure the set has a length of more than one, and then pop it:

import requests
from requests_html import HTMLSession
import sys

link = "http://www.tvil.me/view/93/4/8/v/%D7%90%D7%99%D7%99_%D7%96%D7%95%D7%9E%D7%91%D7%99_IZombie.html"
enter_episodes = HTMLSession().get(link)
page = enter_episodes.html
s = page.xpath("//*[@class='view-watch-button']/a")
for l in s:
    link = l.links
    if len(link) > 0: # make sure it has a value
        print(link.pop()) # get the last value (in your case, the only one)
maor10
  • 1,645
  • 18
  • 28