Skip to content Skip to sidebar Skip to footer

How To Extract The Value From The By Using Selenium

So i'm using selenium webdriver to parse date from web site by (class_name, tag_name, Xpath, css_selector) and all my attempts to fetch data are unsuccessful. And in this exapmple

Solution 1:

you have put "tr' in soup.find_all('tr') so you tr(table) header. if you put 'td' there then you will get td(row) data. When reading the table, you can also try pandas.read_html method which in many scenarios will be helpful.

import pandas as pd
from bs4 import BeautifulSoup
html_src="""
<tabledata-vdata-qa="table"class"table"><trdata-v><thdata-v> Name </th><thdata-v> Last_name </th><thdata-v> Phone </th><thdata-v> City </th><thdata-v> Salary </th>
      </tr data-v>
   <trdata-vdata-qa="table-row"><tddata-vclass="table-name not-editable">Tetyana</td><tddata-vclass="table-last-name not-editable">Ferguson</td><tddata-vclass="table-phone not-editable">252-823-1658</td><tddata-vclass="table-city not-editable">Tarboro</td><tddata-vclass="table-salary not-editable">10000</td>
      </tr data-v>
   <trdata-vdata-qa="table-row"><tddata-vclass="table-name not-editable">Alyonka</td><tddata-vclass="table-last-name not-editable">Andrews</td><tddata-vclass="table-phone not-editable">603-608-7504</td><tddata-vclass="table-city not-editable">Northwood</td><tddata-vclass="table-salary not-editable">12000</td>
      </tr data-v>
</table>
"""

option 1:

df=pd.read_html(html_src)
print(df[0].head(10))
#output
 Name Last_name         Phone       City  Salary
0  Tetyana  Ferguson  252-823-1658    Tarboro   10000
1  Alyonka   Andrews  603-608-7504  Northwood   12000

option 2:

soup=BeautifulSoup(html_src)
foreach in soup.find_all("td"):
    print(each.get_text())
#output:
Tetyana
Ferguson
252-823-1658
Tarboro
10000
Alyonka
Andrews
603-608-7504
Northwood
12000

Post a Comment for "How To Extract The Value From The By Using Selenium"