1

Thanks for the help with the previous, a bit longer problem @QHarr and @DebanjanB

This one is uncomplicated and comes from me being a total beginner.

I need to scrape the image location from this snippet from webauto.de + a click on the gallery

<li class="slide" style="">
    <img class="image" src="https://www.webauto.de/img/vc/de/0/1/2/19482/pan/1735h_1" style="max-width: 640px; max-height: 480px; width: 100%; height: auto; left: 50%; top: 50%; margin-left: -320px; margin-top: -240px;" alt=""></li>

And either

find_elements_by_css_selector('.slide > img')
find_elements_by_css_selector('li > img')
find_elements_by_xpath("//li[@class='slide']/img]"

leaves me with a blank list instead of a list of addressess.

The second thing is I need to select a subgroup from a JS dropdown on hasznaltauto.hu

<select id="hirdetesszemelyautosearch-modell_id" class="form-control hidegroups" name="HirdetesSzemelyautoSearch[modell_id]" data-live-search="false" data-header="Modell" data-krajee-depdrop="depdrop_fdcef640" disabled="disabled">
    <optgroup label="FIESTA">
        <option value="540" class="opt">FIESTA (1001)</option></optgroup>

And I used a logical continuation of what was provided to me but but it throws 'tuple index out of range'

find_element_by_xpath("//select[@id='hirdetesszemelyautosearch-modell_id']/optgroup[@label='{}']/option[contains(text(), '{}')]".format('FIESTA')).click()
7
  • find_elements uses the implicit wait time you have specify yourself. Have you tried using find_element_by_css_selector instead of elements? Alternatively, have you tried setting the implicit wait time to say 3 seconds? Also I would suggest using the css-selector ".slide .image", but that is up to you Commented Nov 28, 2018 at 13:47
  • Do not ask two questions in single ticket. These issues are not related Commented Nov 28, 2018 at 13:50
  • 1
    lol ticket... that is how it feels sometimes Commented Nov 28, 2018 at 13:53
  • @g_uint "two questions in single question" sounds confusing Commented Nov 28, 2018 at 14:00
  • Yes, I have tried put the script to sleep for 3 secs till it all loads and nothing, the element instead of elementS here is my mistake, I've had it the right way in the script when I used it, rewritten it on SO with a mistake. Commented Nov 28, 2018 at 14:01

2 Answers 2

1

for full size image you need extract it in iframe

iframe = WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.ID, "sb-player")))
driver.switch_to.frame(iframe)
images = driver.find_elements_by_css_selector('.slide > img')
Sign up to request clarification or add additional context in comments.

1 Comment

This is it, it would probably take me while to google it out. Thank you very much.
1

You could use a CSS selector to grab all the image links. I wasn't sure what you meant by address but have used class selector to grab address under gallery.

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

d = webdriver.Chrome()
d.get("https://www.webauto.de/site/de/auto-detail/v-id/121078258-1/fahrzeug/FORD-Fiesta-Style-1,3l-44kW-5-Gang-!-Nur-an-Gewerbe/Export-!-/Gebrauchtwagen/Limousine/silber/Benzin/44-KW-60-PS/Wesseling")
elements = WebDriverWait(d,5).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "[src^='https://www.webauto.de/img/']")))
linkList = [element.get_attribute('src') for element in elements]
print(linkList)
print(d.find_element_by_css_selector('.contactdata').text)

#d.quit()

1 Comment

This works too, thanks. Although the solution from @ewwink is shorter and more intuitive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.