how to get the image hyperlink by using the selenium package.
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://m.imdb.com/feature/bornondate")
elements = driver.find_elements_by_xpath("//a[@class='poster ']")
li = [["Name","Movie Title","Image"]]
for i in elements:
print i.find_element_by_tag_name("img") ##I am not sure how to get the URL
new_line= i.text.splitlines()
#print new_line[0] , " " , new_line[1]
li.append(new_line)
print li
Writing the data to CSV file
with open ('imdb.csv','wb')as fp:
a = csv.writer(fp, delimiter=',')
a.writerows(li)
To get a element property like src you need to call the get_attribute('attr_name') property.
You just need to add the following code to your for cycle:
for i in elements:
image = i.find_element_by_tag_name("img")
img_src = image.get_attribute("src")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With