/
xddxdd
/
Python
Обзор
Документация
Войти
/
xddxdd
/
Python
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
web_programming/crawl_google_results.py
38 строк
1002 B
Christian Clauss
Lukazlim: Replace dependency `requests` with `httpx` (#12744)
14 май 2025, 04:42
Не верифицирован
14 май 2025, 04:42
a2fa32c
Код
Авторство
О чём код?
# /// script # requires-python = ">=3.13" # dependencies = [ # "beautifulsoup4", # "fake-useragent", # "httpx", # ] # /// import sys import webbrowser import httpx from bs4 import BeautifulSoup from fake_useragent import UserAgent if __name__ == "__main__": print("Googling.....") url = "https://www.google.com/search?q=" + " ".join(sys.argv[1:]) res = httpx.get( url, headers={"UserAgent": UserAgent().random}, timeout=10, follow_redirects=True, ) # res.raise_for_status() with open("project1a.html", "wb") as out_file: # only for knowing the class for data in res.iter_content(10000): out_file.write(data) soup = BeautifulSoup(res.text, "html.parser") links = list(soup.select(".eZt8xd"))[:5] print(len(links)) for link in links: if link.text == "Maps": webbrowser.open(link.get("href")) else: webbrowser.open(f"https://google.com{link.get('href')}")