Python crawler not finding specific Xpath

BubblewrapBeast

I asked my previous question here:

Xpath pulling number in table but nothing after next span

This worked and i managed to see the number i wanted in a firefox plugin called xpath checker. the results show below.

enter image description here

so I know i can find this number with this xpath, but when trying to run a python scrpit to find and save the number it says it cannot find it.

try:
    views = browser.find_element_by_xpath("//div[@class='video-details-inside']/table//span[@class='added-time']/preceding-sibling::text()")
except NoSuchElementException:
    print "NO views"
    views = 'n/a'
    pass  

I no that pass is not best practice but i am just testing this at the moment trying to find the number. I'm wondering if i need to change something on the end of the xpath like .text as the xpath checker normally shows a results a little differently. Like below:

enter image description here

i needed to use the xpath i gave rather than the one used in the above picture because i only want the number and not the date. You can see part of the source in my previous question.

Thanks in advance! scratching my head here.

alecxe

The xpath used in find_element_by_xpath() has to point to an element, not a text node and not an attribute. This is a critical thing here.

The easiest approach here would be to:

  • get the td's text (parent)
  • get the span's text (child)
  • remove child's text from parent's

Code:

span = browser.find_element_by_xpath("//div[@class='video-details-inside']/table//span[@class='added-time']")
td = span.find_element_by_xpath('..')
views = td.text.replace(span.text, '').strip()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Selenium - Python Safari WebDriver - not finding element by xpath

From Java

Finding specific digit pattern with regex in python

From Dev

Python--Finding Parent Keys for a specific value in a nested dictionary

From Dev

finding a specific split string in CSV file [Python]

From Dev

Quickly finding an Xpath with R

From Dev

Finding Elements Relatively by XPath

From Dev

Finding an equation that results in a specific integer, Python

From Dev

Finding specific frame in URL to scrape data using Python BeautifulSoup

From Dev

Python lxml's XPath not finding <ul> in <p> tags

From Dev

Selenium Python Finding actual xPath of current node within loop

From Dev

finding a specific value from list of dictionary in python

From Dev

Python: Finding nearest integer value to specific integer

From Dev

Finding elements by xpath pattern in Selenium python

From Dev

Python finding numbers from a list that satisfy a specific condition

From Dev

Selenium & Python: Finding elements with dynamic XPATH

From Dev

Xpath ancestor finding div

From Dev

Finding specific values and replacing them by others. Python

From Dev

python can't specific xpath for <a> tag

From Dev

Python - Finding and multiplying an integer after specific word

From Dev

Quickly finding an Xpath with R

From Dev

Python Code for Finding Specific Parameters

From Dev

Xpath finding in the html code

From Dev

finding xpath to the value

From Dev

Python lxml's XPath not finding <ul> in <p> tags

From Dev

Finding a Mean of an Attribute for a Specific Class in Python

From Dev

ExCan't seem to get Xpath to work for finding specific nodes

From Dev

Finding a specific node using Xpath and Linq

From Dev

Python scraping xpath get <a> with specific <span>

From Dev

XPath not finding any results

Related Related

  1. 1

    Selenium - Python Safari WebDriver - not finding element by xpath

  2. 2

    Finding specific digit pattern with regex in python

  3. 3

    Python--Finding Parent Keys for a specific value in a nested dictionary

  4. 4

    finding a specific split string in CSV file [Python]

  5. 5

    Quickly finding an Xpath with R

  6. 6

    Finding Elements Relatively by XPath

  7. 7

    Finding an equation that results in a specific integer, Python

  8. 8

    Finding specific frame in URL to scrape data using Python BeautifulSoup

  9. 9

    Python lxml's XPath not finding <ul> in <p> tags

  10. 10

    Selenium Python Finding actual xPath of current node within loop

  11. 11

    finding a specific value from list of dictionary in python

  12. 12

    Python: Finding nearest integer value to specific integer

  13. 13

    Finding elements by xpath pattern in Selenium python

  14. 14

    Python finding numbers from a list that satisfy a specific condition

  15. 15

    Selenium & Python: Finding elements with dynamic XPATH

  16. 16

    Xpath ancestor finding div

  17. 17

    Finding specific values and replacing them by others. Python

  18. 18

    python can't specific xpath for <a> tag

  19. 19

    Python - Finding and multiplying an integer after specific word

  20. 20

    Quickly finding an Xpath with R

  21. 21

    Python Code for Finding Specific Parameters

  22. 22

    Xpath finding in the html code

  23. 23

    finding xpath to the value

  24. 24

    Python lxml's XPath not finding <ul> in <p> tags

  25. 25

    Finding a Mean of an Attribute for a Specific Class in Python

  26. 26

    ExCan't seem to get Xpath to work for finding specific nodes

  27. 27

    Finding a specific node using Xpath and Linq

  28. 28

    Python scraping xpath get <a> with specific <span>

  29. 29

    XPath not finding any results

HotTag

Archive