I am writing a web scraper using python queries.
Each page is more than 1 MB, but the actual data that I need to extract is very early in the flow of the document, so I spend time downloading a lot of unnecessary data.
If possible, I would like to stop the download as soon as the necessary data appears in the source code of the document in order to save time.
For example, I only want to extract the text in the "abc" Div, the rest of the document is useless:
<html>
<head>
<title>My site</title>
</head>
<body>
<div id="abc">blah blah...</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris fermentum molestie ligula, a pharetra eros mollis ut.</p>
<p>Quisque auctor volutpat lobortis. Vestibulum pellentesque lacus sapien, quis vulputate enim mollis a. Vestibulum ultrices fermentum urna ac sodales.</p>
<p>Nunc sit amet augue at dolor fermentum ultrices. Curabitur faucibus porttitor vehicula. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>Etiam sed leo at ipsum blandit dignissim ut a est.</p>
</body>
</html>
I am currently just doing:
r = requests.get(URL)
source
share