![]() Then I open the first picture: def open_first_picture(self): Print("Successfully searched for: " + keyword) _element_by_xpath(search_input).send_keys(keyword) """ Method that searches for a username and navigates to nth profile in the results where n corresponds to the index""" It could be used on the "Explore" page or simply on an user's profil page.įirst, to navigate to a profil page from Instagram's main page, I create a xPath for the "SearchBox" and a xPath to the element in the dropdown menu results corresponding to the index. I implemented a function that likes all the picture from an Instagram page. Heart_icon = driver.find_element_by_xpath(my_xpath) # Get xpath of heart icon of the 19th post. Return f'xpath=//article/div/section/span/button/span' Return heart icon xpath corresponding to n-post. So you can manage to get the number of the post you desire and then click it: def get_heart_icon_xpath(post_num): The first number near "article" corresponds to the number of the post. The xpath of the icon of the third post is: xpath=//article/div/section/span/button/spanĪnd so on. ![]() The xpath of the icon of the second post is: xpath=//article/div/section/span/button/span The xpath of the icon of the first post is: xpath=//button/span After some research I found that the xpath of the heart icon below left the post behaves like that: Now let's talk about possible solutions and them implementations. If you really need using Selenium I also recommend downloading Selenium IDE add-on for Chrome here since it can save you much time, believe me. It would make your bot much simpler, more readable and most of all lighter and faster. First of all, in your case it is recommended to use the official Instagram Api for Python ( documentation here on github).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |