简体   繁体   English

有没有可能从 find_elements_by_class 获取图像“src”的方法,它只返回 None

[英]Is there any possible way to get image "src" from find_elements_by_class it just all returning None

I get 250 Total results.我得到 250 个总结果。 I tried to get 10 of the first result's image src but all return None.我试图获取第一个结果的图像 src 中的 10 个,但都返回 None。 If i switch to use XPATH it can't be done automatically because there are too many of them to be manually selected.如果我切换到使用 XPATH 它不能自动完成,因为它们太多需要手动选择。

historylist = WebDriverWait(driver, 100).until(
    EC.presence_of_all_elements_located((By.CLASS_NAME, "coinflip-list__item.coinflip-history-list__item")))
print(f"Total {len(historylist)}")
for x in range(10):
    print(historylist[x].get_attribute("src"))

Total 250 Printing out first 10: <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="7bb1f785-409c-42c8-a85e-b6a7abd9d7be")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="4c445a89-003a-4e42-95b5-4dd0648d3a99")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="a0d21128-055d-4320-aae1-f1bebb532c2d")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="7606d8a6-332b-4584-932f-da0a8203918b")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="619896b8-b79d-4dba-b130-869a758402f7")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="d20d2480-b7e8-49e3-a66d-127c021d133e")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="4a6088总共 250 打印出前 10 个: <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="7bb1f785-409c-42c8-a85e-b6a7abd9d7be")> <selenium.webdriver.remote.webelement.WebElement ( session="d6ac99726310ff2fc4b6070ea0ab7fec", element="4c445a89-003a-4e42-95b5-4dd0648d3a99")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="a0d21128-055d-4320-aae1-f1bebb532c2d ")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="7606d8a6-332b-4584-932f-da0a8203918b")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac9972630abfec2 ", element="619896b8-b79d-4dba-b130-869a758402f7")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="d20d2480-b7e8-49e3-a66d-127c021d3e")> selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="4a6088 9a-58a4-4a77-a033-9303b001fbfa")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="0514a847-0571-4415-b6e6-d9cb96294525")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="8b150b8f-31ec-4090-b983-6a5992f97e41")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="7f909f2d-3459-47ba-9520-04979d958ddd")> 9a-58a4-4a77-a033-9303b001fbfa")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="0514a847-0571-4415-b6e6-d9cb96294525".webdriver.mote .webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0ab7fec", element="8b150b8f-31ec-4090-b983-6a5992f97e41")> <selenium.webdriver.remote.webelement.WebElement (session="d6ac99726310ff2fc4b6070ea0b7fe" 47ba-9520-04979d958ddd")>

That's the output.那是 output。

It looks like your use of By.CLASS_NAME is incorrect.您对By.CLASS_NAME的使用似乎不正确。 Here这里

historylist = WebDriverWait(driver, 100).until(
    EC.presence_of_all_elements_located((By.CLASS_NAME, "coinflip-list__item.coinflip-history-list__item")))

CLASS_NAME or find_element_by_class_name or find_elements_by_class_name accepts only a single class. CLASS_NAMEfind_element_by_class_namefind_elements_by_class_name仅接受单个 class。 Compound classes are not working.复合类不起作用。

Change it to By.CSS_SELECTOR :将其更改为By.CSS_SELECTOR

historylist = WebDriverWait(driver, 100).until(
    EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".coinflip-list__item.coinflip-history-list__item")))

Where coinflip-list__item and coinflip-history-list__item are class names in a single html tag.其中coinflip-list__itemcoinflip-history-list__item是单个 html 标签中的 class 名称。

Check here for description: https://selenium-python.readthedocs.io/locating-elements.html#locating-elements-by-class-name .在这里查看描述: https://selenium-python.readthedocs.io/locating-elements.html#locating-elements-by-class-name

Second , try using visibility_of_all_elements_located instead of presence_of_all_elements_located .其次,尝试使用visibility_of_all_elements_located而不是presence_of_all_elements_located

Other than that, check that your locator is correct.除此之外,请检查您的定位器是否正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 soup.find_all 和 find_elements_by_class 返回没有找到元素 - soup.find_all and find_elements_by_class return no elements found 有什么方法可以从cli中找到python中函数的所有可能的kwargs? - Any way to find all possible kwargs for a function in python from cli? Beautifulsoup 类 find 正在返回 None - Beautifulsoup class find is returning None BeautifulSoup类找到返回无 - BeautifulSoup class find returning None 如何在 selenium python 中仅使用一个类从任何网站获取所有数据 - How to get all the data from any website with just one class in selenium python Python正则表达式从字符串获取所有图像src&#39; - Python regular expression to get all image src from a string' 有什么方法可以获取所有可能的 Python 类变量,包括没有值的变量? - Any way to get all possible Python class variables, including ones without values? 如何从 XML 列中获取元素值或到达 python 中的元素 - 不返回任何内容 - How to get element values from an XML column or reaching elements within python - keep returning none 查找数组中某些元素的所有组合 - Find all combinations of just some elements of an array 我想从 class 中刮掉这 400 个,如图所示,但它没有返回。 有什么解决办法吗? - I want to scrape this 400 from a class as shown in the picture, but it's returning none. Any solutions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM