Skip to main content
https://travis-ci.org/sashgorokhov/python-ninegag.svg?branch=master https://badge.fury.io/py/python-ninegag.svg

Python library to get stuff from 9gag.com

Installation

Via pip:

pip install python-ninegag

Usage

pyninegag.get_sections()

Returns dict of 9gag sections, where keys are capitalized sections names, and values are their urls.

Example output:

{'Fresh': 'http://9gag.com/fresh',
'Cute Animals': 'http://9gag.com/cute',
'Comic': 'http://9gag.com/comic',
'Food': 'http://9gag.com/food',
'GIF': 'http://9gag.com/gif',
'Cosplay': 'http://9gag.com/cosplay',
'Geeky': 'http://9gag.com/geeky',
'Girl': 'http://9gag.com/girl',
'Funny': 'http://9gag.com/funny',
'Design': 'http://9gag.com/design',
'WTF': 'http://9gag.com/wtf',
'NSFW': 'http://9gag.com/nsfw',
'Trending': 'http://9gag.com/trending',
'Timely': 'http://9gag.com/timely',
'Meme': 'http://9gag.com/meme',
'Hot': 'http://9gag.com/hot'
}

NOTE: NSFW section will return zero articles (empty iterable) since watching this section requires user login, which is not supported by this library.

These values are not hardcoded and will be generated on first request. Values are cached.

pyninegag.get_articles(url, max_pages=1)

Return iterable with all articles found on given url. max_pages - how many pages of results to parse. If None - all available. Default 1 - only first page.

pyninegag.get_articles(pyninegag.BASE_URL)

Will return all articles on main 9gag page.

Example output:

[
{
    'id': 'a1MEzz6',
    'title': 'Jumping into the abyss',
    'data': {
        'type': 'gif',
        'url': 'http://img-9gag-fun.9cache.com/photo/a1MEzz6_460sa.gif'
    },
    'comments': '163',
    'votes': '10709',
    'url': 'http://9gag.com/gag/a1MEzz6'
},
{
    'id': 'agVEP3g',
    'title': 'Made of crab',
    'data': {
        'type': 'image',
        'url': 'http://img-9gag-fun.9cache.com/photo/agVEP3g_700b_v1.jpg'
    },
    'comments': '257',
    'votes': '10053',
    'url': 'http://9gag.com/gag/agVEP3g'
}
]

Article type can be one of gif, image or longpost. Longpost is just a very tall image.

pyninegag.get_by_section(section_name, max_pages=1)

Return iterable with all articles found in given section. Section name must be one of the keys of pyninegag.get_sections(). If not found, ValueError will be raised.

There is also a logger pyninegag enabled that logs exceptions and warnings of parsing errors. All errors contain article id and url in message for easier debugging of problems.

Metadata

Release files for python-ninegag 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-ninegag 1.0
File Size Uploaded
python-ninegag-1.0.zip 5.5 kB Details

Release files / python-ninegag-1.0.zip

Download URL python-ninegag-1.0.zip
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f7c818add86211bb10492e45ea84e3f1dd3214b254eb64801f25188dd23e61ac
BLAKE2b-256 checksum
How to use checksums
90b8dfe3d4119c7c007754f6a3189349cfdadcf54d680483383fa3a6f012485e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0 This release

1 release file

0.5

1 release file

0.4.2

0.4

1 release file

0.3.2

1 release file

0.3.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page