Advertisement
Rnery

Bs4..

Apr 6th, 2022 (edited)
859
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | Source Code | 1 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. from bs4 import BeautifulSoup as bs
  5. from requests import get, exceptions
  6. from re import findall
  7.  
  8. USER_AGENT = "Nery App 1.0"
  9.  
  10. BASE_URL = "https://www.google.com/search?q={}"
  11.  
  12.  
  13. def main():
  14.     while True:
  15.         search_term = input("\nSearch: ").strip()
  16.         if not search_term:
  17.             continue
  18.  
  19.         try:
  20.             response = get(BASE_URL.format(search_term), headers={"User-Agent": USER_AGENT})
  21.             soup = bs(response.content, "lxml")
  22.  
  23.             for link in soup.find_all("a"):
  24.                 href = link.get("href")
  25.                 if href and findall(r"(http|https)\:\/\/.*", href):
  26.                     print(href)
  27.         except exceptions.RequestException as err:
  28.             print(f"Error: {err}")
  29.  
  30.  
  31. if __name__ == "__main__":
  32.     main()
Tags: python python3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement