B
B
badrbot2018-10-21 20:03:01
Python
badrbot, 2018-10-21 20:03:01

How to copy a domain on selenium?

I wrote the code

from selenium import webdriver


driver = webdriver.Chrome()
driver.get("https://gdz-putina.net/11-klass-algebra-mordkovich#task?t=prgrph-1-1")
content = driver.find_element_by_css_selector('.task img ')
content.click()
content1 = content.find_element_by_tag_name(img)
src = content1.get_attribute('src')
print(src)

And it throws an error
How do I parse a link to an image or just copy the domain on the site?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2018-10-22
@acrytzat

first: you need to add the location address of your chromedriver.exe file
second: it is important to wait for the element you need to load on the page - for this, use WebDriverWait
and third: in adding content1 - I forgot the quotes to the tag name.
In general, it works for me with the following code (enter your own value for path):

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait

path = 'C:\Python34\my_progs\chromedriver.exe'
driver = webdriver.Chrome(executable_path=path)
driver.get("https://gdz-putina.net/11-klass-algebra-mordkovich#task?t=prgrph-1-1")

WebDriverWait(driver, 20).until(
            lambda d: d.find_element_by_class_name('task'))
content = driver.find_element_by_class_name('task')

WebDriverWait(content, 20).until(
            lambda d: d.find_element_by_tag_name('img'))
content = content.find_element_by_tag_name('img')
content.click()

WebDriverWait(driver, 20).until(
            lambda d: d.find_element_by_tag_name('img'))
content1 = driver.find_element_by_tag_name('img')
src = content1.get_attribute('src')
print(src)   # https://gdz-putina.net/attachments/images/tasks/000/001/887/0002/5a6491b599d46.png
driver.quit()

T
Talik, 2018-10-23
@Talik0507

The text of the error in the studio ... there are no wangers here.
In general,
the content1 = content.find_element_by_tag_name(img)
tag name should be in quotes right away.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question