Skip to main content

Fanficapi

An unofficial API (more like story and author metadata scraper) for fanfiction.net and archiveofourown.org written in python

Fanficapi is simple and easy to use python package for scraping story and author metadata from fanfiction.net and archiveofourown.org.

Features

  • Get story metadata from FFN and AO3 from a story link
  • Get author metadata from FFN and AO3 from author link
  • Simple keyword search to get the story link from FFN or AO3

Note: This was just my November project that I made for learning html scraping using python, I know the code is sh*t and just wanted to save it as a private repo, but recently I noticed all my other scrapers stopped working because of FFN's cloudflare protection. This one's working because it's based on undetected-chromedriver. So, if you feel it might be useful to you, here it is!

Installation

Installation using pip:

pip install fanficapi or pip3 install fanficapi

Manual installation by cloning the github repository:

git clone https://github.com/lonely-code-cube/fanficapi
cd fanficapi
python3 setup.py install

Note: The github repository usually has latest updates and features, so it might contain more bugs

Usage

For getting ao3 story metadata:

import fanficapi

ao3 = fanficapi.AO3()
print (ao3.getStoryMeta("https://archiveofourown.org/works/5105735/chapters/11745368"))

The getStoryMeta() function returns a dictionary that looks like:

{'title': 'When In Doubt',
'author': 'JesWithOneEss',
'rating': 'Teen And Up Audiences',
'archiveWarnings': 'Creator Chose Not To Use Archive Warnings',
'category': 'F/M',
'fandom': 'Harry Potter - J. K. Rowling',
'relationship': 'Hermione Granger/Ron Weasley',
'characters': ['Hermione Granger', 'Ron Weasley'],
'tags': ['romione', 'Ron and Hermione - Freeform','Angst', 'Missing Moments', 'Deathly Hallows','book canon', 'Harry Potter - Freeform', 'book 7', 'rhr'],
'published_date': '2015-10-30',
'word_count': '13921',
'chapter_count': '4',
'comments': '8',
'kudos': '76',
'hits': '4217'}

For getting ffn story metadata:

import fanficapi

ffn = fanficapi.FFN(headless=False, delay=5)
print (ffn.getStoryMeta("https://www.fanfiction.net/s/7562379/1/Australia"))

It is not recommended to use the headless mode as increases chances of getting detected by cloudflare, nevertheless, depends on when your are using and your luck

The getStoryMeta() returns a dictionary that looks like:

{'story_name': 'Australia',
'author_name': 'MsBinns',
'Rated': 'Fiction M',
'Language': 'English',
'Genre': 'Romance/Angst',
'Character': 'Ron W., Hermione G.',
'Chapters': '45',
'Words': '340,509',
'Reviews': '2,555',
'Favs': '2,026',
'Follows': '1,456',
'Updated': 'Aug 31, 2014',
'Published': 'Nov 19, 2011',
'Status': 'Complete',
'id': '7562379'}
  • The fanficapi.AO3() takes only one optional argument AO3(textMode: bool) which is by default False
  • The fanficapi.FFN() takes 4 optional argument FFN(textMode: bool, headless: bool, executable_path: str, delay: int)
  • By default undetected-chromedriver is run in headless mode, set this to False if scraping doesnot work
  • If you don't have chrome added to path, download the chromedriver from their wesite or use the one in the repo, set executable_path = "/path/of/chromedriver"
  • If scraping doesn't work even after disableing headless mode, try increasing the delay (default is 5)
  • Text mode just informs what's happening if you don't planning on printing the result but want to know the status

License

GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007

I am not responsible for any kind of loss caused by the usage of this software. This is just a free software, use it at your own risk.

Metadata

Release files for fanficapi 1.0.5

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

Source distribution (sdist)

Source distribution for fanficapi 1.0.5
File Size Uploaded
fanficapi-1.0.5.tar.gz 8.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fanficapi 1.0.5
File Interpreter ABI Platform
fanficapi-1.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 28.8 kB

Release files / fanficapi-1.0.5.tar.gz

Download URL fanficapi-1.0.5.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d389249f0f89ced1a09d1b43a2e4127024f4d062f12d68dd64880754f9f96894
BLAKE2b-256 checksum
How to use checksums
dbc42de86783e165def05a34f7047747f3b45dd0baa6f88a41b680e12165dbeb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release files / fanficapi-1.0.5-py3-none-any.whl

Download URL fanficapi-1.0.5-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
908aff3a6d9d8f88ac7eb9014600c1822737a78ed6b433406d664887498b8ab8
BLAKE2b-256 checksum
How to use checksums
726695fd2ffb98170040c0b7a78360a9898c1daf9b1069cad4996cc2df9d8f1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release history Release notifications | RSS feed

This release

1.0.5 This release

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

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