python - 如何将 selenium webelement 转换为 python 中的字符串变量

标签 python selenium

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/

相关文章:

python - Sklearn,高斯过程 : XA and XB must have the same number of columns

python-3.x - ImportError : sys. meta_path 为 None,Python 可能正在关闭

selenium - 如何使用 Selenium WebDriver 进行可行的 Web 冒烟测试?

java - table.findElements(By.tagName ("td") 在 RemoteWebDriver/Internet Explorer 中失败

python - 如何访问标签内的标签(获取标签文本等值)?如何获取(段落)p 标签内 h1 标签的值?

python - Pandas,从 DataFrame 生成一个表,其中多列合并到新索引中

python - 在负载均衡器 : django-channels 后面运行多个 daphne 实例

python - 使用带有 webdriver.find 函数的 python 过滤与 selenium 进行网络抓取

创建二维 numpy 数组的 Pythonic 方式

python - 如何选择和替换列中的相似出现项