How to convert a selenium webelement to string variable in python

2024/11/13 22:41:17
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)

The output is a selenium webelement in the form of a list. I want to convert it into a string variable so that the list can contain all the jobtitles in text format. If I can get assistance in this it will be great. Thanks in advance.

Answer

In case, if you need a list of links to each job:

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

In case, if you want just a job titles list:

job_list = []
jobtitlebuttons = driver.find_elements_by_class_name('job-title-text')
for job in jobtitlebuttons:job_list.append(job.text)
https://en.xdnf.cn/q/71935.html

Related Q&A

Why are session methods unbound in sqlalchemy using sqlite?

Code replicating the error:from sqlalchemy import create_engine, Table, Column, Integer from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmakerBase = declarative…

Combining Tkinter and win32ui makes Python crash on exit

While building a basic app using the winapi with Python 2.7 (Im on Windows 8.1), I tried to add a small Tkinter gui to the program. The problem is, whenever I close the app window, Python crashes compl…

horizontal tree with graphviz_layout

in python, with networkx. I can plot a vertical tree with : g=nx.balanced_tree(2,4)pos = nx.graphviz_layout(g, prog=dot)nx.draw(g,pos,labels=b_all, node_size=500)plt.show()similar to [root]|| |nod…

Finding first n primes? [duplicate]

This question already has answers here:Closed 12 years ago.Possible Duplicate:Fastest way to list all primes below N in python Although I already have written a function to find all primes under n (pr…

Scipy.optimize.root does not converge in Python while Matlab fsolve works, why?

I am trying to find the root y of a function called f using Python. Here is my code:def f(y):w,p1,p2,p3,p4,p5,p6 = y[:7] t1 = w - 0.99006633*(p1**0.5) - (-1.010067)*((1-p1))t2 = w - 22.7235687*(p2**0.…

Query CPU ID from Python?

How I can find processor id with py2.6, windows OS?I know that there is pycpuid, but I cant compile this under 2.6.

Recover from segfault in Python

I have a few functions in my code that are randomly causing SegmentationFault error. Ive identified them by enabling the faulthandler. Im a bit stuck and have no idea how to reliably eliminate this pro…

python and using self in methods

From what I read/understand, the self parameter is similiar to this.Is that true?If its optional, what would you do if self wasnt passed into the method?

How to extract only characters from image?

I have this type of image from that I only want to extract the characters.After binarization, I am getting this image img = cv2.imread(the_image.jpg) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) thresh…

connect to Azure SQL database via pyodbc

I use pyodbc to connect to my local SQL database which works withoout problems.SQLSERVERLOCAL=Driver={SQL Server Native Client 11.0};Server=(localdb)\\v11.0;integrated security = true;DATABASE=eodba; c…