Kaila Shanmukh
Kaila Shanmukh

Reputation: 131

I want to append 4 text variables into a variable called job and print the text of job variable

I am currently scraping Linkedin Job directory using selenium in python shell

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()

driver.get('https://www.linkedin.com/jobs/search?
locationId=sg%3A0&f_TP=1%2C2&orig=FCTD&trk=jobs_jserp_posted_one_week')
a = driver.find_elements_by_class_name('job-title-text')
b = driver.find_elements_by_class_name('company-name-text')
c = driver.find_elements_by_class_name('job-location')
d = driver.find_elements_by_class_name('job-description')
#There are 50 pages of jobs therefore I specified a range of 55
for e in range(55):

   for g in a:

      print(g.text)

   for h in b:

      print(h.text)

   for i in c:

      print(i.text)

   for j in d:

      print(j.text)

k = driver.find_element_by_class_name('next-btn')
k.click()
Job = []
Job.append(a)
Job.append(b)
Job.append(c)
Job.append(d)

   for l in Job:
          print(l.text)

This code is not working and I have been struggling and tried various methods of solving this issue. It will be great if I can get the correct solution.

Upvotes: 1

Views: 142

Answers (2)

HiPownedBi
HiPownedBi

Reputation: 195

i am not really understand your question. maybe u can get some ideas from enumerate(list)

for example:

word_list=['go','have', 'fun', 'good']
name_list=['1.txt','2.txt','3.txt','4.txt']

for i, word in enumerate(word_list):
   print i ### it is the position of each element
   print word ### it is the each element of word_list
   print name_list[i] ### it is the each element of name_list 

for further, u may modify the lists such as join the lists, append....

Upvotes: 0

Kernel
Kernel

Reputation: 731

for e in range(55):

   for g in a:

      print(g.text)
      job.append(g)

   for h in b:

      print(h.text)
      job.append(h)

   for i in c:

      print(i.text)
      job.append(i)

   for j in d:

      print(j.text)
      job.append(j)

Maybe you should get job list like this.

Upvotes: 0

Related Questions