selectolax
selectolax copied to clipboard
examples for other functions?
Hi there,
Can we get examples when / how to use .next, .prev? And say in a div you have 2 a tags that does not have any classes and have texts in between them. What's the best way to grab things?
eg.
<td class="no_cell you_lite">
<a href="https://scrapethis.com/index.php?thread=98800"><img src="https://scrapethis.com/the_post.gif" alt="My post" title="My post"></a>
Sun, 16 June 2024, 20:51:11
<br>
by <a href="https://scrapethis.com">Brand</a>
</td>
Thanks
You can get away with css selectors here:
parser = HTMLParser(html)
for item in parser.css('td.no_cell a'):
print(item.text, item.attributes)
@rushter , nice that worked. what's the best way to grab the text on the same level (Sun, 16 June 2024, 20:51:11). i only see it when i do ...text(deep=True)
@rushter , nice that worked. what's the best way to grab the text on the same level (
Sun, 16 June 2024, 20:51:11). i only see it when i do...text(deep=True)
Just do item.next.text() for the first a tag you got from css selector.