нужна помощь! Я пытаюсь получить "RC0402JR-070RL" из HTML ниже.
Вот HTML:
<td class="tr-mfgPartNumber">
<a itemprop="url" href="/product-detail/en/yageo/RC0402JR-070RL/311-0.0JRCT-ND/729353">
<span itemprop="name">RC0402JR-070RL</span>
</a>
</td>
Я могу найти текст с помощью команды xpath ниже. Уже проверено с помощью xpather.com, которые указывают на правильный текст.
//table[@id='productTable']//td[contains(.,'Cut')]/preceding-sibling::td[@class='tr-mfgPartNumber']//span[@itemprop='name']
Но я не могу напечатать его на Python, используя следующую команду:
browser.find_element_by_xpath("//table[@id='productTable']//td[contains(.,'Cut')]/preceding-sibling::td[@class='tr-mfgPartNumber']//span").text
Я могу печатать другие тексты на языке Python, но не этот.
Есть идеи? Вот мой код Pyhthon:
from selenium import webdriver
browser = webdriver.PhantomJS(executable_path='C:/Phantom/phantomjs-2.1.1-windows/bin/phantomjs.exe')
browser.set_window_size(1124, 850)
url = "https://www.digikey.com/products/en?keywords=RC0402JR-070RL"
browser.find_element_by_xpath("//table[@id='productTable']//td[contains(.,'Cut')]/preceding-sibling::td[@class='tr-mfgPartNumber']//span").text
Вот сообщение об ошибке, которое я получаю:
*
*Traceback (most recent call last):
File "<pyshell#114>", line 1, in <module>
browser.find_element_by_xpath("//table[@id='productTable']//td[contains(.,'Cut')]/preceding-sibling::td[@class='tr-mfgPartNumber']//span").text
File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 365, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 843, in find_element
'value': value})['value']
File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 308, in execute
self.error_handler.check_response(response)
File "C:\Python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: {"errorMessage":"Unable to find element with xpath '//table[@id='productTable']//td[contains(.,'Cut')]/preceding-sibling::td[@class='tr-mfgPartNumber']//span'","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"189","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:54137","User-Agent":"Python http auth"},"httpVersion":"1.1","method":"POST","post":"{\"using\": \"xpath\", \"value\": \"//table[@id='productTable']//td[contains(.,'Cut')]/preceding-sibling::td[@class='tr-mfgPartNumber']//span\", \"sessionId\": \"820657b0-90a8-11e9-9d2e-6935905b705f\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/820657b0-90a8-11e9-9d2e-6935905b705f/element"}}
Screenshot: available via screen*
*