I was doing webs craping of nokri.com
using selenium, after getting the elements using xpath when I am trying it to put in for loop I am getting error this is my code
job_details=driver.find_elements_by_xpath('//a[@]')
job_details
for i in job_details
i=i.text
job_details.append(i)
job_details
I am getting str
object has no attribute 'text'
error
elements I got already but not sure why I am getting this error
I tried with range(len) also but then I got int
object has no attribute 'text'
error
CodePudding user response:
Apparently, i
is a str
already.
So you dont have to do i.text
.
Try removing the line
i = i.text
If that doesn't do, please share the full error traceback.
Also, I wouldn't recommend to use job_details
variable (that you are reading) to also write your answer.
CodePudding user response:
You are missing :
in loop. Also, you should initialize job_details
.
Please use .get_attribute('innerText')
Code :
job_details_list = driver.find_elements_by_xpath("//a[@class='title fw500 ellipsis']")
job_details = []
for i in job_details_list:
a = i.get_attribute('innerText')
print(a)
job_details.append(a)
and print it like this :
print(job_details)