Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- """
- Script to scrape q-posts
- Requirements:
- - Python
- - requests_html
- - typer
- Installation:
- python3 -m pip install requests_html typer
- """
- import time
- from typing import Generator, List, Tuple
- import typer
- from requests_html import Element, HTMLResponse, HTMLSession
- app = typer.Typer()
- def get_range(start: int, stop: int) -> Generator[Tuple[int, str], None, None]:
- session = HTMLSession()
- for n in range(start, stop + 1):
- req: HTMLResponse = session.get(f"https://qalerts.app/?n={n}")
- if req.status_code == 200:
- results: List[Element] = req.html.find(".dont-break-out")
- for result in results:
- yield n, result.text
- time.sleep(1.5)
- @app.command()
- def print_drops(start: int, stop: int) -> None:
- """
- Print q-posts from start to stop in console
- """
- last_n = None
- for n, drop in get_range(start, stop):
- if last_n != n:
- print(f"== Drop {n:04} ==")
- print(drop)
- print()
- print()
- last_n = n
- if __name__ == "__main__":
- app()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement