Home > Enterprise >  Website scraping - How to get parameters from div class
Website scraping - How to get parameters from div class

Time:01-04

I wath to extract the information about the year, kms and color from this part of the html code using python's BeautifulSoup. Can someone help me out?

                    <h3  id="techParams">Tech parms</h3>
                    <div >
                        <div >
                            <table >
                                <tr>
                                    <th>Year</th><td>2014</td>
                                </tr>
                                <tr>
                                    <th>Kms</th><td>103 472 km</td>
                                </tr>
                                <tr>
                                    <th>Color</th><td>white</td>
                                </tr>
                            </table>
                        </div>

I tried:

res = requests.get(website)
soup = BeautifulSoup(res.content, "html.parser")
results = soup.find('div', {'class': 'techParamsRow general'})
print(results)

But it's not finding anything. Thank you!

CodePudding user response:

If I understand you correctly, you can do what you what by using css selectors:

data = soup.select('table.transparentTable tr')
for d in data:
  row = d.select('th,td')
  print(row[0].text,":",row[1].text)

Output:

Year : 2014
Kms : 103 472 km
Color : white

CodePudding user response:

This was already answered in multiple questions:

  •  Tags:  
  • Related