I am scraping li tags and want to stop at a specific place in the html. I do not want the li tags that are after this point in the html.
I am usnig python 3.7, beautifulsoup4, here is a link to example site data
<li class="s-item" data-view="mi:1686|iid:1">...</li>
<li class="s-item" data-view="mi:1686|iid:2">...</li>
<li class="s-item" data-view="mi:1686|iid:3">...</li>
<div class="srp-river-answer srp-river-answer--REWRITE_START" data-view="mi:1706|iid:1">...</div>
<li class="s-item" data-view="mi:1686|iid:4">...</li>
<li class="s-item" data-view="mi:1686|iid:5">...</li>
<li class="s-item" data-view="mi:1686|iid:6">...</li>
Goal is to get all li tags before the div statement and none after the div statement. The number of li tags before and after vary by page. I have tried and cannot find a way to have beautifulsoup scrape until a point in the html.
I currently retrieve all li tags with the following
only_li = SoupStrainer('li')
soup_li = BeautifulSoup(response.text, 'lxml', parse_only = only_li)
sale_details = soup_li.find_all('li', attrs={'class':'s-item','data-view':True})
for sale in sale_details:
some scrape code