Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

+-----------------------+

| Aplicação Python |
+-----------------------+
|
v
+-----------------------+
| Requests |
+-----------------------+
|
v
+-----------------------+
| Google Search |
+-----------------------+
|
v
+-----------------------+
| BeautifulSoup |
+-----------------------+

import requests
from bs4 import BeautifulSoup

def busca_google(query):
url = f"https://www.google.com/search?q={query}"
headers = {'User-Agent': 'Mozilla/5.0'}
response = requests.get(url, headers=headers)

if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
links = soup.find_all('a')

for link in links:


href = link.get('href')
if href.startswith('/url?q='):
print(link.text, href.split('/url?q=')[1].split('&')[0])

busca_google("Python web scraping")

You might also like