【问题标题】:How to convert a selenium webelement to string variable in python如何在python中将硒webelement转换为字符串变量
【发布时间】:2016-10-13 03:27:33
【问题描述】:
from selenium import webdriver
from time import sleep
from selenium.common.exceptions import NoSuchAttributeException
from selenium.common.exceptions import NoSuchElementException
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')
jobtitlebutton = driver.find_elements_by_class_name('job-title-link')
print(jobtitlebutton)

输出是一个列表形式的 selenium webelement。我想将其转换为字符串变量,以便列表可以包含文本格式的所有职位。 如果我能在这方面得到帮助,那就太好了。提前致谢。

【问题讨论】:

  • 您需要链接列表还是工作列表(例如“数据中心技术员”、“测试经理”)?

标签: python selenium


【解决方案1】:

如果您需要每个作业的链接列表:

job_list = []
jobtitlebuttons = driver.find_elements_by_class_name('job-title-link')
for job in jobtitlebuttons:
    job_list.append(job.get_attribute('href'))

如果您只需要职位列表:

job_list = []
jobtitlebuttons = driver.find_elements_by_class_name('job-title-text')
for job in jobtitlebuttons:
    job_list.append(job.text)

【讨论】:

  • 非常感谢它对我的帮助很大。
  • 我也想知道如何单击每个职位并提取类名称为“内容”的职位描述。
  • 我猜你应该遍历链接的job_list 并执行description = "/n".join([i.text for i in driver.find_elements_by_xpath('//div[@class="content"]//ul/li')]) 之类的操作
  • 非常感谢。这肯定有帮助
猜你喜欢
  • 2012-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多