Issue
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 class="topNavTitle" id="techParams">Tech parms</h3>
<div class="techParamsRow general">
<div class="col col12M pr20">
<table class="transparentTable">
<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!
Solution
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
Answered By - Jack Fleeting
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.