Skip to content

Instantly share code, notes, and snippets.

@master-of-zen
Created October 6, 2019 18:21
Show Gist options
  • Save master-of-zen/11dee1e25c39d1a3862b145a91d3bc21 to your computer and use it in GitHub Desktop.
Save master-of-zen/11dee1e25c39d1a3862b145a91d3bc21 to your computer and use it in GitHub Desktop.
def search(booktup) -> list:
try:
# Scrap libgen search page for books data
logger.info(f'Searching for book: {booktup.title}')
all_books = []
for page in range(1, 10):
url = f'http://libgen.is/search.php?&{urlencode({"req": booktup.title, "res": 100, "page":page})}'
soup = BeautifulSoup(get(url).text, 'lxml')
books = soup.find_all('tr')[3:-1] # Get all books with their info
all_books.extend(extract_books(books))
logging.info(f'Found books: {len(all_books), all_books}')
if booktup.ext or booktup.lang or booktup.year:
all_books = sort_books(all_books, booktup)
return all_books
except:
print(f'something got wrong')
return []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment