【问题标题】:I want to append 4 text variables into a variable called job and print the text of job variable我想将 4 个文本变量附加到一个名为 job 的变量中并打印 job 变量的文本
【发布时间】:2016-12-03 16:34:31
【问题描述】:

我目前正在 python shell 中使用 selenium 抓取 Linkedin Job 目录

从硒导入网络驱动程序

从 selenium.webdriver.common.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)

此代码不起作用,我一直在努力尝试解决此问题的各种方法。如果我能得到正确的解决方案,那就太好了。

【问题讨论】:

  • 请正确格式化您的代码并说明什么不工作。如果您收到任何错误消息,请显示错误消息。 How to Ask

标签: python selenium


【解决方案1】:

我不太明白你的问题。也许你可以从 enumerate(list) 中得到一些想法

例如:

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 

进一步,你可以修改列表,例如加入列表,追加......

【讨论】:

    【解决方案2】:
    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)
    

    也许你应该得到这样的工作清单。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-17
      • 2019-11-23
      • 1970-01-01
      • 2018-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多