Package: libgen-scraper
Libgen ScraperA set of utilities for searching and retrieving information from the Library Genesis service. It includes functionality for searching, filtering, and accessing details about the available literature.Enjoy open and automated access to knowledge!Table of ContentsInstallationGeneral UsageSearchAccessing ResultsDownloadingSaving ResultsAboutInstallationTo install the library, run the following command:pipinstalllibgen-scraperUsageSearchTo perform a search, use thesearch_family of functions:importlibgen_scraperaslgnon_fiction=lg.search_non_fiction("Geology of Mars")Search results can also be filtered using thefilterparameter, which accepts a dictionary of...Columnsand corresponding regex patterns.
Here's some more examples including more advanced parameters:importlibgen_scraperaslg# Find at most 2 non-fiction books published by Helion.# Books shall be in Polish and about Java.# Print the title of the first book in each chunk of results as they are received.non_fiction=lg.search_non_fiction("Helion",search_in_fields=lg.NonFictionSearchField.PUBLISHER,filter={lg.NonFictionColumns.LANGUAGE:r'Polish',lg.NonFictionColumns.TITLE:r'[Jj]ava',},limit=2,chunk_callback=lambdaresults:print(results.title(0)),libgen_mirror="http://libgen.rs",)# non_fiction is at this point a NonFictionResults object that contains all the results of the search.# non_fiction.data is a Pandas DataFrame containing the results in a tabular, unstructured format.# Find at most 10 fiction books with "Harry Potter" in the title.# Books shall be in English, in PDF format. Wildcards are not allowed in the query.fiction=lg.search_fiction("Harry Potter",search_criteria=lg.FictionSearchCriteria.TITLE,wildcards=False,language='English',format=lg.FictionSearchFormat.PDF,# Filters are also supported.limit=10,# Chunk callback is also supported.)# Find at most 10 scientific articles about social media.articles=lg.search_articles("Social Media",# Filters are also supported.limit=10,# Chunk callback is also supported.)Accessing ResultsThe search results are encapsulated in...Resultsobjects that provide methods to access information about each book.
Each kind of search has its own...Resultsclass with custom methods matching the available information.
For example, some of the functionality ofNonFictionResultsis:# Accessing book details:print(non_fiction.title(0))# Print the title of the first book.print(non_fiction.authors(0))print(non_fiction.mirrors(0))DownloadingEvery...Resultsobject has adownload_linksmethod that can fetch download links for a specific book.
Multiple mirrors can be used to download the book, and the mirrors are scraped in order as returned by.mirrors(i).
By default only the first mirror is used, but you can specify the number of mirrors to use with thelimit_mirrorsparameter.
This will however increase the time it takes to fetch the download links.fromurllib.requestimporturlretrieve# Download the first book from the first 2 mirrors.# Mirrors at the beginning of the list are preferred.download_links=non_fiction.download_links(0,limit_mirrors=2)urlretrieve(download_links[0],non_fiction.id(0)+".pdf")Saving ResultsEach...Resultsobject encapsulates a Pandas DataFrame with the results in a tabular, unstructured format.
You can save this DataFrame to a CSV file using Pandas.
Saved data can be loaded back by manually constructing a...Resultsobject with DataFrame as the argument.importpandasaspd# Save NonFictionResults to a CSV filenon_fiction.data.to_csv("results.csv",index=False)# Load the results from a CSV filedata=pd.read_csv("results.csv")non_fiction=NonFictionResults(data)AboutThis library is not affiliated with the Library Genesis service in any way.
It is a community project, and is not officially supported by Library Genesis nor does it promote the use of the service.The library is licensed under the MIT license.