Home>

My program enters Instagram on a given Hesteg, and opens the first post to receive a description of the description or put like a selenium.

The code simply does not detect an element, some method I did not use (CSS_Selector, Find_element_BY_CLASS, FIND_Element_BY_XPATH).

Import Re
Import Random
Import Time.
Import Requests.
Import LXml.
From Selenium Import WebDriver
GetHashtag= 'Moscow'
url= 'https://www.instagram.com/explore/tags/' + GetHashtag
Print (URL)
Driver= WebDriver.chrome ()
DRIVER.GET (URL)
Element= driver.find_element_BY_XPATH ('/HTML /Body /DIV [1] /Section /Main /Article /Div [1] /DIV /DIV /DIV [1] /DIV [1] /A /DIV /DIV [2] ')
element.click ()

I get an error:

Selenium.common.Exceptions.nosuchelementException: Message: No Such Element: Unable to Locate Element: {"Method": "Xpath", "Selector": "/HTML /Body /Div [1] /Section /Main /Article /Div [1] /div /div /div [1] /div [1] /A /DIV /DIV [2]}

I read that the page may not be up to the end, so I added

driver.implicitly_wait (10)

Now the page opens and the code does not go further, I get the following warnings:

[12: 38: 45.454] USB: USB_Device_Handle_win.cc:1048 Failed to Read Descriptor from Node Connection: ╧╧shyukhfshehhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhє (0x1f)

Thank you in advance!

  • Answer # 1

    You need to add user agent (because Servak ​​sees it is a program). Still in Selenium there is a method to wait for the download of the item (choose what is on the page is guaranteed).

    Enlarge waiting time, for verification.

    But it seems to me that because of the agent.

    I connected the usergoent, however the program also flies with a second error. 'Opts= options () opts.add_argument (' -user-agent= "chrome /42.0.2311.135" ') GetHashtag=' Moscow 'url=' Instagram.com/explore/tags' + Gethashtag Print (URL) Driver= WebDriver.chrome (Chrome_Options= Opts) '

    Flake2021-07-22 12:05:23
  • Answer # 2

    You need to add user agent (because Servak ​​sees it is a program). Still in Selenium there is a method to wait for the download of the item (choose what is on the page is guaranteed).

    Enlarge waiting time, for verification.

    But it seems to me that because of the agent.

    I connected the usergoent, however the program also flies with a second error. 'Opts= options () opts.add_argument (' -user-agent= "chrome /42.0.2311.135" ') GetHashtag=' Moscow 'url=' Instagram.com/explore/tags' + Gethashtag Print (URL) Driver= WebDriver.chrome (Chrome_Options= Opts) '

    Flake2021-07-22 12:05:23