What I would like to achieve
I would like to make a website that allows users to scrape information from other websites. My goal is to achieve something as follows:
- User presses "scrape"
- When the scraping process begins, Django renders a view with a loading message and a "stop" button
- If the user presses the "stop" button, or if the scraping process terminates, a view with the scraping results is shown
Current state
At the moment, I have a very simple scraping website with a horrible user experience. After the user presses scrape, I render a view similar to the following one:
def scraping_view(request, scraper_args):
scrape_results = scrape(scraper_args) # Very long function!
return render(request, 'scrape_view.html', scrape_results )
This is a bad idea, as the scrape function takes a long time, and the user experience is terrible.
My (probably bad) idea
My idea was to:
- launch a celery task and render an intermediary view with the loading message and a "stop" button
- let the celery task store the scrape results somewhere (where?)
- find a way to revoke the task if the user presses the "stop" button
- retrieve the results of the celery task when the task is finished or when "stop" is being pressed
- cancel the scrape results after the page is closed, as I am simply interested in showing them on the website
As I am new to Django, I cannot evaluate if my idea is feasible or if it makes sense at all. Does anyone have a solution to propose, an alternative solution, or some examples to share? Thanks!