selectolax icon indicating copy to clipboard operation
selectolax copied to clipboard

examples for other functions?

Open vash-knives opened this issue 1 year ago • 3 comments

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

vash-knives avatar Jun 17 '24 07:06 vash-knives

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 avatar Jun 17 '24 10:06 rushter

@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)

vash-knives avatar Jun 17 '24 14:06 vash-knives

@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.

rushter avatar Jun 17 '24 15:06 rushter