无法获得元素硒PYTHON

时间:2020-02-14 13:42:39

标签: python selenium web-scraping

我需要从页面获取元素,然后将其打印出来 但是它总是打印出来的:

[<selenium.webdriver.remote.webelement.WebElement (session="636e500d9db221d6b7b10b8d7849e1b5", 
    element="4f0ccc3b-44b0-4cf2-abd4-95a70278bf77")>...

我的代码:

film_player = free_filmy_url + filmPlayerPart
dr = webdriver.Chrome()
dr.get(film_player)
captcha_button = dr.find_element_by_xpath('/html/body/form/div/input[1]')
captcha_items = dr.find_elements_by_class_name('captchaMyImg')
print(captcha_items)

2 个答案:

答案 0 :(得分:0)

您可以遍历captcha_items并打印每个。

for captcha_item in captcha_items:
    # you can access each item here as "captcha_item"
    print(captcha_item.text()) # if you are trying to print the text 

答案 1 :(得分:0)

通过您的代码行:

captcha_items = dr.find_elements_by_class_name('captchaMyImg')
print(captcha_items)

您正在打印元素。

相反,您必须寻找打印元素的属性,并且可以使用以下解决方案:

print([my_elem.get_attribute("attribute") for my_elem in dr.find_elements_by_class_name('captchaMyImg')])

注意:您需要将文本属性替换为这些元素的任何现有属性,例如srchrefinnerHTML