Code Monkey home page Code Monkey logo

Comments (3)

jarun avatar jarun commented on May 22, 2024

I'll take a look tomorrow.

from googler.

zmwangx avatar zmwangx commented on May 22, 2024

By the way, I'm thinking about adding some dev scripts to facilitate development. Current idea:

> tree devbin
devbin
├── __pycache__
│   └── googler.cpython-35.pyc
├── googler.py -> ../googler
└── parse

1 directory, 3 files

Content of parse:

#!/usr/bin/env python3

import argparse
import json

import googler

def main():
    argparser = argparse.ArgumentParser(description='Parse Google responses.')
    argparser.add_argument('-N', '--news', action='store_true',
                           help='parse as Google News responses')
    argparser.add_argument('files', nargs='+', metavar='FILE',
                           help="HTML file with Google's response body")
    args = argparser.parse_args()
    for fn in args.files:
        with open(fn, encoding='utf-8') as fp:
            htmlparser = googler.GoogleParser(news=args.news)
            htmlparser.feed(fp.read())
            results_object = [r.jsonizable_object() for r in htmlparser.results]
            print(json.dumps(results_object, indent=2, sort_keys=True, ensure_ascii=False))

if __name__ == '__main__':
    main()

Invocation:

> devbin/parse -h
usage: parse [-h] [-N] FILE [FILE ...]

Parse Google responses.

positional arguments:
  FILE        HTML file with Google's response body

optional arguments:
  -h, --help  show this help message and exit
  -N, --news  parse as Google News responses
> devbin/parse /Volumes/ramdisk/googler-response-2qmy246b  # Good
[
  {
    "abstract": "HELLO! Online brings you the latest celebrity & royal news from the UK & around the world, magazine exclusives, celeb babies, weddings, pregnancies and ...",
    "title": "HELLO! Online: celebrity & royal news, magazine, babies, weddings ...",
    "url": "http://www.hellomagazine.com/"
  },
  {
    "abstract": "Hello, it's me. I was wondering if after all these years you'd like to meet. To go over everything. They say that time's supposed to heal ya. But I ain't done much ...",
    "title": "ADELE LYRICS - Hello - A-Z Lyrics",
    "url": "http://www.azlyrics.com/lyrics/adele/hello.html"
  },
  {
    "abstract": "hello connects you with people and content around your passions. Show the world who you are, express what you love, and create meaningful connections.",
    "title": "hello network",
    "url": "http://www.hello.com/"
  },
  {
    "abstract": "\"Hello\" is a song by English singer Adele. It was released on 23 October 2015 by XL Recordings as the lead single from her third studio album, 25 (2015). Adele ...",
    "title": "Hello (Adele song) - Wikipedia, the free encyclopedia",
    "url": "https://en.wikipedia.org/wiki/Hello_(Adele_song)"
  },
  {
    "abstract": "Watch Hello by Adele online at vevo.com. Discover the latest music videos by Adele on Vevo.",
    "title": "Hello - Adele - Vevo",
    "url": "http://www.vevo.com/watch/adele/Hello/GBH481500074"
  },
  {
    "abstract": "Make your phone smarter with Hello. Built by Messenger just for Android, Hello combines info from Facebook with the contact info on your phone so it's easy to ...",
    "title": "Hello — Caller ID & Blocking - Android Apps on Google Play",
    "url": "https://play.google.com/store/apps/details?id=com.facebook.phone&hl=en"
  },
  {
    "abstract": "HELLO! 1779396 likes · 92804 talking about this. The official Facebook page for HELLO! magazine & http://www.hellomagazine.com/ FOLLOW US @...",
    "title": "HELLO! - Facebook",
    "url": "https://www.facebook.com/hello/"
  },
  {
    "abstract": "Listen to Hello in full in the Spotify app. Play on Spotify. ℗ 2015 XL Recordings Ltd., under exclusive license to Columbia Records, a Division of Sony Music ...",
    "title": "Hello by Adele on Spotify",
    "url": "https://open.spotify.com/album/1Eo1pg2D4beFgf3HFTJTMc"
  }
]
> devbin/parse /Volumes/ramdisk/googler-response-unjwqp8g  # Bad
[]

from googler.

jarun avatar jarun commented on May 22, 2024

👍

from googler.

Related Issues (20)

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.