1

I wish I could get the text below but what I got is ''.

Any tips to go further? This is my code and the following is from the source page.

x = element.find_elements_by_xpath('//*[@id="detailsContent"]/div[2]/ul/li[5]/span[3]')[0].text
<span class="text-sm md:text-base text-primary cursor-pointer hover:underline" onclick="$(this).swapWithNext();gaTrack('Interact', 'MoreDetails-Show', 'NAICS Code', 1, true);">show</span>
<span class="text-sm md:text-base hidden">332992, Small Arms Ammunition Manufacturing</span>
3
  • Any chance you could provide a link to the page or the full src (html) for the page? If not, it's impossible to rule out why either: A.which part of your xpath isn't working properly, or B. The text you're trying to scrape isn't grabbed by the default .text attribute (I don't think this is the issue). Additionally, you may want to try the find by class method instead. Commented Mar 19, 2020 at 21:51
  • meta.stackexchange.com/a/5235/289619 Commented Apr 3, 2020 at 6:56
  • Please remember to mark the answer please Commented Apr 19, 2020 at 9:15

1 Answer 1

1

To get the text, try using get_attribute("innerHTML")

Example

x = element.find_elements_by_xpath(
    '//*[@id="detailsContent"]/div[2]/ul/li[5]/span[3]'
).get_attribute("innerHTML")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.