【问题标题】:Can't get element SELENIUM PYTHON无法获取元素 SELENIUM PYTHON
【发布时间】:2020-05-30 07:45:39
【问题描述】:

我需要从页面中获取元素然后打印出来 但它总是打印出这个:

[<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)

【问题讨论】:

  • 看起来像写的那样工作。问题是什么?你期待什么?你试过什么?

标签: python selenium web-scraping


【解决方案1】:

您可以遍历 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 

【讨论】:

    【解决方案2】:

    通过您的代码行:

    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')])
    

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

    【讨论】:

      猜你喜欢
      • 2021-04-05
      • 1970-01-01
      • 2021-07-04
      • 1970-01-01
      • 2022-01-03
      • 2021-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多