Issue
Good time of the day!
While working on the scraping project I have faced some issues. I have to scrape string values from the table, basing my search on the string of tr as in following:
span = list()
span.append({
"Price":soup.find("p", class_="classified__price").find("span",class_="sr-only").text,
"Kitchen":soup.find("th",text="Kitchen type").find_next(class_="classified-table__data").text
})
Considering if I leave .text
at the end of the value in the "Kitchen" key - prints nothing, however
span = list()
span.append({
"Price":soup.find("p", class_="classified__price").find("span",class_="sr-only").text,
"Kitchen":soup.find("th",text="Kitchen type").find_next(class_="classified-table__data")
})
results in
[{'Price': '410000€', 'Kitchen': <td class="classified-table__data">
Installed
</td>}]
All help is very much appreciated!
Solution
The output you want is actually under the next element, to find it you can use the .next_element
method:
span = list()
span.append({
"Price":soup.find("p", class_="classified__price").find("span",class_="sr-only").text,
"Kitchen":soup.find("th",text="Kitchen type").find_next(class_="classified-table__data").next_element.strip()
})
print(span)
Output:
[{'Price': '410000€', 'Kitchen': 'Installed'}]
Answered By - MendelG
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.