GithubHelp home page GithubHelp logo

gla_web_scrapper's Introduction

Web Scraping Project and Performance Comparison

Getting Started

  1. Set up a Python virtual environment by running the following command in the terminal:
    python3 -m venv venv2934
    
  2. Activate the virtual environment:
    source venv2934/bin/activate
    
  3. Install all dependencies within the virtual environment:
    pip3 install -r requirements.txt
    

Optimized vs. Unoptimized Solution

1. Optimized Solution (Asyncio)

Running Time

3 seconds / 100 URLs (for this project)

Thought Process

After evaluating three options for optimization, Asyncio is the most suitable solution. The three options considered are:

  • Asyncio: Preferred for managing many waiting tasks, particularly effective in solving I/O bottlenecks.
  • Multiprocessing: Maximizes performance on CPU-intensive tasks, suitable for solving CPU-bound problems. However, it may cause overload and is not ideal for lightweight processes.
  • Threading: Suitable for parallel tasks that share data with minimal CPU usage. However, in this project, threads could be cumbersome to manage and are not the best fit.
    async with aiohttp.ClientSession() as session:
        tasks = []
        for url in urls:
            task = fetch_webpage_content(session, url)
            tasks.append(task)

        # gather is run all the tasks concurrently
        all_fetched_content = await asyncio.gather(*tasks)

The key differences in the optimized solution are:

  • Usage of aiohttp instead of the requests library because aiohttp can handle asynchronous data fetching efficiently.
  • Instead of processing tasks upon completion of others, asyncio allows us to execute multiple asynchronous functions concurrently to optimize performance by overcoming I/O bottlenecks.
  • The code snippet above (await asyncio.gather(*task)) executes all tasks on the list concurrently.

2. Unoptimized Solution (Requests)

Running Time

124 seconds / 100 URLs (for this project)

Thought Process

  • This option utilizes the requests library.
    • Cons: requests is not designed for asynchronous processes.
    • Pros: requests.get(url, timeout=10) allows us to set a timeout limit to prevent undue load. (as per below image)
    sitemap_content = requests.get(sitemap_url, timeout=10).text

gla_web_scrapper's People

Contributors

luciensday avatar

Watchers

 avatar

gla_web_scrapper's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.