【发布时间】:2019-06-25 04:13:59
【问题描述】:
对 Selenium 来说非常新,但我无法从这个网站选择我想要的元素。在这种情况下,我使用 Chrome 的“复制 XPath 工具”获得了 x_path。基本上,我希望从网站中提取 CID 文本(在本例中为 4004),但我的代码似乎无法做到这一点。任何帮助将不胜感激!
我也尝试过使用 CSS 选择器方法,但它返回相同的错误。
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.binary_location = '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary'
driver= webdriver.Chrome()
chem_name = "D008294"
url = "https://pubchem.ncbi.nlm.nih.gov/#query=" + chem_name
driver.get(url)
elements = driver.find_elements_by_xpath('//*[@id="collection-results-container"]/div/div/div[2]/ul/li/div/div/div/div[2]/div[2]/div[2]/span/a/span/span')
driver.close()
print(elements.text)
截至目前,这是我收到的错误:'list' object has no attribute 'text'
【问题讨论】:
标签: selenium