简体   繁体   English

无法获取元素硒 PYTHON

[英]Can't get element SELENIUM PYTHON

I need to get element from page and then print it out But it always print out this:我需要从页面获取元素然后打印出来但它总是打印出来:

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

My code:我的代码:

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)

You can iterate through the captcha_items and print each of them.您可以遍历 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 

Through your lines of code:通过你的代码行:

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

You are printing the elements.您正在打印元素。

Rather you must be looking to print an attribute of the elements and you can use the following solution:相反,您必须希望打印元素的属性,您可以使用以下解决方案:

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

Note : You need to replace the text attribute with any of the existing attributes for those elements, eg src , href , innerHTML , etc.注意:您需要将 text属性替换为这些元素的任何现有属性,例如srchrefinnerHTML等。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM