Git Product home page Git Product logo

bmsl's Introduction

NEW VERSION

https://github.com/maksimKorzh/tiny_scraper

BMSL

Bare minimum web scraping library

Disclaimer

Please don't take it too serious - it's made more like for educational purposes rather than for production

How to use

########################################
#
# Test script showing how to use BMSL
#
#                 by
#
# scraping http://quotes.toscrape.com/
#
########################################

# import packages assuming "BMSL" folder containing files "request.py" and "parser.py"
# is located in current working directory along with this file "quotes.py".
# Please see /src/BMSL/test folder for the example project layout

from BMSL import request
from BMSL import parser
import csv

# make HTTP GET request
html = request.get(url='http://quotes.toscrape.com/', payload={}, headers={})

# data extraction logic
quotes = parser.find(content=html, query=['span', ('class', 'text'), 'text'])
authors = parser.find(content=html, query=['small', ('class', 'author'), 'text'])
about = []

# extract all links
about_text = parser.find(content=html, query=['a', (), 'text'])
about_href = parser.find(content=html, query=['a', (), 'href'])

# extract "about" links
for index in range(0, len(about_href)):
    if about_text[index] == '(about)':
        about.append(about_href[index])

# loop over all items
for index in range(0, len(quotes)):
    # write output to CSV file
    with open('quotes.csv', 'a') as f:
        # create CSV writer
        writer = csv.writer(f)
        
        # write line
        writer.writerow([quotes[index], authors[index], about[index]])

Implementing "request.py"

IMAGE ALT TEXT HERE

Implementing "parser.py"

IMAGE ALT TEXT HERE

bmsl's People

Contributors

maksimkorzh avatar

Watchers

 avatar

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.