Package: fanficapi
FanficapiAn unofficial API (more like story and author metadata scraper) for fanfiction.net and archiveofourown.org written in pythonFanficapi is simple and easy to use python package for scraping story and author metadata from fanfiction.net and archiveofourown.org.FeaturesGet story metadata from FFN and AO3 from a story linkGet author metadata from FFN and AO3 from author linkSimple keyword search to get the story link from FFN or AO3Note: 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!InstallationInstallation using pip:pip install fanficapiorpip3 install fanficapiManual installation by cloning the github repository:git clone https://github.com/lonely-code-cube/fanficapi
cd fanficapi
python3 setup.py installNote: The github repository usually has latest updates and features, so it might contain more bugsUsageFor getting ao3 story metadata:importfanficapiao3=fanficapi.AO3()print(ao3.getStoryMeta("https://archiveofourown.org/works/5105735/chapters/11745368"))ThegetStoryMeta()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:importfanficapiffn=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 luckThegetStoryMeta()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'}Thefanficapi.AO3()takes only one optional argumentAO3(textMode: bool)which is by default FalseThefanficapi.FFN()takes 4 optional argumentFFN(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 workIf you don't have chrome added to path, download the chromedriver from their wesite or use the one in the repo, setexecutable_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 statusLicenseGNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007I 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.