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 网络元素。我想将其转换为字符串变量,以便列表可以包含文本格式的所有职位。 如果我能在这方面得到帮助,那就太好了。提前致谢。
最佳答案
以防万一,如果您需要每个工作的链接列表:
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)
关于python - 如何将 selenium webelement 转换为 python 中的字符串变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40011816/