Giter Site home page Giter Site logo

ai-landscraper's Introduction

AI-landscraper

Searches Google (CSE API) for AI and nonprofit related content, and scrapes results using playwright-python. Primary purpose is to create a text dataset for use by LLM's in projects that aim to understand the nonprofit sector.

Install

pip install git+git://github.com/Giving-Tuesday/AI-landscraper.git

Setup

The Google Custom Search Engine (CSE) requires your own API token and search engine ID.

docs: https://developers.google.com/custom-search/json-api/v1/reference/cse/list

Once you get your credentials, create a credentials.json file in the main folder and save them like this:

{"GOOGLE_CSE_API_KEY": <somereallylongkey>, "GOOGLE_SEARCH_ENGINE_ID": <anotheruniquecode>}

So they can be read like this:

        with open('credentials.json','r') as f:
            creds = json.load(f)
        self.api_key = [creds['GOOGLE_CSE_API_KEY']]
        self.search_engine_id= creds['GOOGLE_SEARCH_ENGINE_ID']

Results will appear in data/results.json and scraped page content in data/pages.json.

Using

controller.py -- the main file you run from command line. Or if you want to adjust parameters, you can load it and run it like this:

import controller
controller.main(timeframe='5y', 
    query_date=" after:2020-10-01 before:2023-10-01",
    return_pages=10,
    incl_actors=False)

[Examples of parameters you might want to adjust]

filetype: https://support.google.com/webmasters/answer/35287 You could also customize which file types it saves. The code is currently set to handle HTML pages and ignore PDF pages, but the google search results can separately be customized to fetch or ignore these:

Example filetypes: pdf, rss, xls, xlsx, doc, docx, rtf This allows for multiple filetypes, if passing in a list to search_google function. See: https://stackoverflow.com/questions/18901738/multiple-file-types-search-using-google-custom-search-api for more examples of customizing the search

Customizing search parameters

Look at daily_search.py for the search parameters that are permutatively covered. You can edit these.

mini_scraper

There is also a bare-bones webscraper included in mini_scraper.py but not called in this project. The playwright package offers a superior headless browser that can read javascript rendered pages instead.

ai-landscraper's People

Contributors

marcmaxson avatar titaniumbones avatar

Watchers

Darren Clarke avatar  avatar Parsa Torabian 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.