Ed Mata
Ed Mata

Reputation: 35

I am trying to scrape the names of the companies on "https://dribbble.com/jobs"

When I try the following code it only returns the first item over again. I am new to python so would a appreciate any help.

import pandas as pd 
from selenium import webdriver
from time import sleep
driver = webdriver.Chrome('/Users/user/Downloads/chromedriver_win32/chromedriver')
driver.get('https://dribbble.com/jobs')
assert 'Dribbble' in driver.title 
columns = ['company']
count = 0
jobs = pd.DataFrame(columns=columns)
for item in range(10): 
            company_elem = "job-board-job-title"
            company = driver.find_element_by_class_name(company_elem).text
            item+=1
            jobs.loc[item] = [company]
driver.close()  

Upvotes: 1

Views: 81

Answers (2)

Rola
Rola

Reputation: 1964

You can change one line only,so instead of

company = driver.find_element_by_class_name(company_elem).text

Try

company = driver.find_elements_by_class_name(company_elem)[item].text

and the output will be:

                                     company
1       UI Designer / Animator / Illustrator
2                    Senior Product Designer
3          Freelance Senior Graphic Designer
4    Senior Product Designer, Internal Tools
5                       Sr. Product Designer
6                            User Researcher
7                           Product Designer
8                            Design Director
9                           Product Designer
10  Supply Chain Account Manager - 200163935

Upvotes: 0

Santhosh Reddy
Santhosh Reddy

Reputation: 135

import pandas as pd
from selenium import webdriver
# from time import sleep
driver = webdriver.Chrome(r'E:\data\python\pycharm\chromedriver_win32\chromedriver.exe')
driver.get('https://dribbble.com/jobs')
assert 'Dribbble' in driver.title
columns = ['company']
count = 0
jobs = pd.DataFrame(columns=columns)
# for item in range(10):
# company_elem = "job-board-job-title"
companies = driver.find_elements_by_class_name("job-board-job-title")
for i in companies:
     print(i.text)
# count += 1
# jobs.loc[count] = [company]
# print(jobs)
driver.close()

made few changes to your code now , you need to get all elements instead of 1 where you used find element, use find elements. https://selenium-python.readthedocs.io/locating-elements.html#locating-elements-by-class-name

Upvotes: 1

Related Questions