セレンxpathでテキストをコピーするには? 私はpython seleniumテキストのコピー方法は?
driver.find_elements_by_xpath("//div[@class='rankingItem-value js-countable']").text
を書くとき、私は次のエラーを取得:
Traceback (most recent call last):
File "<stdin>", line 15, in <module>
AttributeError: 'list' object has no attribute 'text'
フルコード:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Firefox()
driver.get('https://www.similarweb.com/')
driver.find_element_by_id("js-swSearch-input").send_keys("www.pornhub.com")
driver.find_element_by_css_selector("button.swSearch-submit").click()
#self.driver.implicitly_wait(30)
time.sleep(10)
content = driver.find_elements_by_xpath("//div[@class='rankingItem-value js-countable']").text
print(content)
私は "22" 1、表にサイトのグローバルランクをコピーする必要があります。どうやって?
を 'のリストを返しますfind_elements_by_xpath'要素。要素を反復し、各要素からテキストを取得する必要があります。 –
可能性の重複[セレンのPythonのXPathで要素を選択する方法](http://stackoverflow.com/questions/19035186/how-to-select-element-with-selenium-python-xpath) – parik