I am trying to print quallity or any variable after the loop but it's not working. It's working before the loops only. How can I use it?
I want to send get request with all this details to link.
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
for x in range(1, 2):
driver.get("http://sparo.live/movies?page=%d" % (x))
text = driver.find_elements_by_xpath("//div[@class='boxALL']/article/a" )
print (len(text))
array = []
info = []
for link in text:
links = link.get_attribute("href")
array.append(links)
for i in array:
driver.get(i)
title = driver.find_element_by_xpath(".//*[@id='wrapper']/div/div/div[1]/h1")
english_title = driver.find_element_by_xpath(".//*[@id='wrapper']/div/div/div[1]/h2")
year = driver.find_element_by_xpath(".//*[@id='wrapper']/div/div/div[1]/div[2]")
geners = driver.find_element_by_xpath(".//*[@id='wrapper']/div/div/div[5]/div[1]/span[1]")
description = driver.find_element_by_xpath(".//*[@id='wrapper']/div/div/div[5]/div[9]/p")
preimg = driver.find_element_by_xpath(".//*[@id='wrapper']/div/div/div[1]/div[1]/img")
img = preimg.get_attribute("src")
quallity = driver.find_element_by_xpath(".//*[@id='tab-content1']/div/div[3]/a/div[1]/p[2]")
pretrailer = driver.find_element_by_xpath(".//*[@id='wrapper']/div/div/div[6]/ul/li/iframe")
trailer = pretrailer.get_attribute("src")
prelinks = driver.find_element_by_xpath(".//*[@id='tab-content1']/div/div[3]/a")
watchonclick = prelinks.get_attribute("onclick")
watchlink = watchonclick.replace('open', 'location.replace')
driver.execute_script(watchlink)
find_div = driver.find_elements_by_xpath("//div[@class='box']/div[2]/a" )
for div in find_div:
links_to_watch = div.get_attribute("href")
break
print ("quallity: '%s'." % quallity.text)
quallitygets printed and you are free to use it after the loop(s). If you aren't, then it's becausearrayhas length0every single time, which can only be due totextbeing similarly having length0. Try printing out these variables and see if you find something other than what you expect.forloops :) What is the point offor x in range(1, 2)? And what is the point of breaking loop after first iteration (infor div in find_div)?