How do I scrape text with no specific class? I have pulled up a past eBay listing that sold via auction. Here is the snippet of code from the heading section.
<h1 class="it-ttl" id="itemTitle" itemprop="name"><span class="g-hdn">Details about </span>2018 Panini Contenders Josh Allen #105 No Feet RC Ticket Auto PSA 10 GEM
I want to be able to scrape just the text "2018 Panini Contenders Josh Allen #105 No Feet RC Ticket Auto PSA 10 GEM" with requests and beautiful soup, but there is no class assigned to that specific text.
Here is the code I have so far…
Currently working on this line.
h1 = soup.find('h1', id="itemTitle")
print(h1)
Any help would be appreciated.
2
Answers
Try using the
find_next()
method withtext=True
, which will return the first text match, and than use.next
to get the next text after that. For example:Output:
You could index into a list comprehension based on stripped_strings generator, or itertools.islice into the generator. The latter I found out was possible from @cobbal