0

In the Xpath Helper plugin, I was able to get the HTML tag content:

QUERY://div[@id="cardModel"]/div[@class="modal-dialog"]/div[@class="modal-content"]//tr[1]/td[1]//tr/td[2]/div/span/text()

RESULTS (1):Enrico

The result is:

Enrico

But in Python:

from selenium import webdriver
from lxml import etree

driver = webdriver.Chrome()
detailUrl = 'https://www.enf.com.cn/3d-energy-1?directory=panel&utm_source=ENF&utm_medium=perc&utm_content=22196&utm_campaign=profiles_panel'
driver.get(detailUrl)
html_ele_detail = etree.HTML(driver.page_source)
time.sleep(5)

companyPhone = html_ele_detail.xpath('//div[@id="cardModel"]/div[@class="modal-dialog"]/div[@class="modal-content"]//tr[1]/td[1]//tr/td[2]/div/span/text()')
print("companyPhone = ", companyPhone)

companyPhone shows empty, what's wrong?Thank you all for solving this problem

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • `//div[@id="cardModel"]/div[@class="modal-dialog"]/div[@class="modal-content"]//tr[1]/td[1]//tr/td[2]/div/span/text()` this does not represent anything in HTMLDOM, Which element you are trying to interact with? – cruisepandey Apr 17 '22 at 05:58

1 Answers1

0

As you are already using the selenium library, you do not need to use etree library.

For this application selenium library is enough

see the example below and adapt for your purpose:

from selenium import webdriver


driver = webdriver.Chrome()
detailUrl = 'your url here'
driver.get(detailUrl)

web_element_text = driver.find_element_by_xpath('your xpath directory here').text

print(web_element_text)

See some other examples in another topic by clicking here

Let me know if this was helpful.