'Datas scrapping from linkedin using selenium
I am trying to use selenium's library on python to scraping compagnies's infos from linkedin.
I have succeed to connect to linkedin with the webdriver. But I am stuck when I try to search for a compagny in the search bar. I would like to search for a compagny and add a location in the filter to have a better result. I have a lot of difficulties with the location's filter because it's using a drop-down list with autocompletion.
So I don't know how I can choose the first element from the drop-down list after writing few characters.
I am using this code.
I send the key word "law office" in the search bar
search = browser.find_element(By.CSS_SELECTOR, "#global-nav-typeahead input")
search.send_keys("law office")
search.send_keys(Keys.RETURN)
Then I am using this code to filter only on compagnies.
browser.find_element_by_xpath("//*[@id='search-reusables__filters-bar']/ul/li[2]/button").click()
The part where I am stuck, trying to select the first element from the autocompletion list.
browser.find_element_by_xpath("//*[@id='artdeco-hoverable-artdeco-gen-111']").send_keys("New York")
browser.find_element_by_xpath("//*[@id='artdeco-hoverable-artdeco-gen-105']").send_keys(Keys.RETURN)
browser.find_element_by_class_name("search-typeahead-v2__hit-info display-flex flex-column").click()
I have to improve this code because the element to add a location is not the same. Then, I can't select the first element of the drop-down list, I have an error message because the element is not found.
I give you the screenshot of the html page :
It would be nice of you, If you can help to fix my code. Thank you very much.
Solution 1:[1]
Don't type "New York" and then hit the back space key (return). Type the full address you need, for example "New York City". This way you will have less options to choose from, and the first one will probably be the one you need.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tal Angel |

