简体   繁体   中英

exist text in ' class elements, but Unable to get text element when I use the selenium in python

I have been trying to get the multiple elements with the same class using 'nested Loop' and Selenium for Python.

The DataFrame used has a column that shows the URL, so I'm using this column in order to connect 'driver'

for i, url in enumerate(df['naver_store_url']):
   driver.get(url+'/review/visitor') 

#try
   all_elements= driver.find_elements(by=By.CLASS_NAME, value = "WoYOw")
   for comment in all_elements:
      default_comment += comment.text +'/'
   review_text_list.append(default_comment) 

The code has been modified as follows:

    try:
    search_review = driver.find_elements(by=By.CLASS_NAME, value= "WoYOw")
    for comment in search_review:
        x = comment.get_attribute('innerText')
        default_comment = default_comment +'/' + x
    comment_house.append(default_comment)

Even if the element has characters, the old code can return an empty string. This is because the element does not have a text property and the value is set to a different property.

so,I had modified a piece of code as follows : .text -> .get_attribute('innerText')

*Please let me know if you have a better way :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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