Git Product home page Git Product logo

cointelegraph-scraper's Introduction

Cointelegraph Scraper

This is an automation tool to fetch articles data from cointelgraph.com. The articles on the homepage of the website are collected and their metadata(including title, author, date, etc.) is saved as output.

Installation

Mac OS

  1. Install brew from here.
  2. Install git and pipenv using brew.
    brew install git pipenv
  3. Clone this repository.
    git clone https://github.com/dub-basu/cointelegraph-scraper/
  4. Install the Python dependencies and create a virtual env using the pipfile provided.
    cd cointelegraph-scraper
    pipenv install
  5. Downlaod the Firefox driver for selenium from here. Extract the tar.gz file and copy the content to any directory in your $PATH.

Usage

  1. Activate the Python environment using pipenv.
    pipenv shell

Download new articles

Download new articles from the website is a two step process.

  1. Step 1: Enter the following command replacing the date in the given format YYYY-MM-DD.
    python main.py step1 --date YYYY-MM-DD
    This will open up a browser instance and keep loading the page till an article is found which was posted before the provided date. All the articles between the current date and the provided date will be download in the form of an HTML file(sources.html by default).
  2. Step 2: Enter the following command replacing the date in the given format YYYY-MM-DD.
    python main.py step2 --date YYYY-MM-DD
    This will parse the URLs of articles obtained in HTML file from step 1 and fetch their data one-by-one.
  3. Once completed, the results will be saved in the downloads directory in the form of CSV files.

Updating existing articles data

  1. Choose this option if you want to update the data present in a CSV file that was obtained from step 2 above.
    python main.py update --filepath <path-to-your-csv-file>
    A new file will be created in the downloads directory.

cointelegraph-scraper's People

Contributors

dub-basu avatar

Watchers

 avatar

cointelegraph-scraper's Issues

Working in ES not in COM

I'm trying to run the code. It works well in the ES (Spanish) version of Cointelegraph but fails on the .COM (English site).

Error:

➜  cointelegraph-scraper (master) ✗ python3 main.py step1 --date 2020-09-14

INFO    : ####### STARTING COINTELEGRAPH SCRAPER #######
INFO    : Starting automated browser window. 
DEBUG   : Found accept button
DEBUG   : Clicked accept button
DEBUG   : Will now load more articles. Date limit: 2020-09-14
CRITICAL: Failed unexpectedly. Check logs.
ERROR   : Exception occured
Traceback (most recent call last):
  File "main.py", line 47, in <module>
    function(date)
  File "main.py", line 11, in step1
    fetch_and_save(date_str, SOURCE_FILE)
  File "/Users/danielpolo/dev/cointelegraph-scraper/scraper.py", line 17, in fetch_and_save
    load_more(driver, date_string)
  File "/Users/danielpolo/dev/cointelegraph-scraper/scraper.py", line 64, in load_more
    last_article_date = string_to_date(get_last_date(driver))
  File "/Users/danielpolo/dev/cointelegraph-scraper/scraper.py", line 41, in get_last_date
    while not is_url_valid(URL + articles_tags[last_index].header.a['href']):
  File "/usr/local/lib/python3.8/site-packages/bs4/element.py", line 1368, in __getitem__
    return self.attrs[key]
KeyError: 'href'

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.