Skip to content

Bad XPath with -p/--person option #17

@D4m13n-contrib

Description

@D4m13n-contrib

Hi,

When I try to use the option -p/--person I got a Python exception with Selenium during the parsing of the page :

$> python phunter.py -p +33666666666
                                                                                                                                                              
                     _._     _,-'""'-._
                    (,-.`._,'(       |\`-/|               q-p
                        `-.-' \ )-`( , o o)              /   \
                            `-    \`_`"'-               (     )
                                                         `-(-'
                                                            )

                            :-----------------Phunter-----------------:
                            |    by Norze ~ Phone number OSINT Tool   |
                            :-----------------------------------------:

[?] What's your browser? Chrome or Firefox? (c/f): f
[>] Driver setup completed

[!] You have 10s for accept
Traceback (most recent call last):
  File "/home/damien/Desktop/Phunter/phunter.py", line 8, in <module>
    asyncio.run(parser())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/damien/Desktop/Phunter/lib/cli.py", line 104, in parser
    Annuaire.annuaire(args.person)
  File "/home/damien/Desktop/Phunter/lib/annuaire.py", line 53, in annuaire
    driver.find_element(By.XPATH, '//*[@id="form_motor_pagesjaunes"]/div/div[2]/div/button').click()
  File "/home/damien/Desktop/Phunter/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 766, in find_element
    return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
  File "/home/damien/Desktop/Phunter/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 380, in execute
    self.error_handler.check_response(response)
  File "/home/damien/Desktop/Phunter/venv/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //*[@id="form_motor_pagesjaunes"]/div/div[2]/div/button; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
Stacktrace:
RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8
WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:193:5
NoSuchElementError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:511:5
dom.find/</<@chrome://remote/content/shared/DOM.sys.mjs:136:16

To solve this issue, I suggest you to modify the XPath like this :

diff --git a/lib/annuaire.py b/lib/annuaire.py
index e0e1af6..790868d 100644
--- a/lib/annuaire.py
+++ b/lib/annuaire.py
@@ -50,7 +50,7 @@ class Annuaire:
         driver.find_element(By.XPATH, '//*[@id="quoiqui"]').send_keys(p_n)
         sleep(1)
 
-        driver.find_element(By.XPATH, '//*[@id="form_motor_pagesjaunes"]/div/div[2]/div/button').click()
+        driver.find_element(By.XPATH, '//*[@id="findId"]').click()
         sleep(1)
 
         try:

Note: only tested with Firefox web browser.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions