import requests
from bs4 import BeautifulSoup
import pandas as pd
URL = "https://www.roendolivros.com.br/"
headers = {
"User-Agent": (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/140.0 Safari/537.36"
)
}
response = requests.get(URL, headers=headers, timeout=30)
if response.status_code == 429:
raise Exception(
"O site retornou HTTP 429 (Too Many Requests). "
"Aguarde alguns minutos antes de tentar novamente."
)
response.raise_for_status()
soup = BeautifulSoup(response.text, "html.parser")
dados = []
Captura os links encontrados na página
for link in soup.find_all("a", href=True):
texto = link.get_text(" ", strip=True)
url = link["href"]
if texto:
dados.append({
"Texto": texto,
"URL": url
})
Cria a planilha
df = pd.DataFrame(dados)
df.to_excel("roendo_livros.xlsx", index=False)
print(f"{len(df)} registros salvos em roendo_livros.xlsx")
import requests
from bs4 import BeautifulSoup
import pandas as pd
URL = "https://www.roendolivros.com.br/"
headers = {
"User-Agent": (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/140.0 Safari/537.36"
)
}
response = requests.get(URL, headers=headers, timeout=30)
if response.status_code == 429:
raise Exception(
"O site retornou HTTP 429 (Too Many Requests). "
"Aguarde alguns minutos antes de tentar novamente."
)
response.raise_for_status()
soup = BeautifulSoup(response.text, "html.parser")
dados = []
Captura os links encontrados na página
for link in soup.find_all("a", href=True):
texto = link.get_text(" ", strip=True)
url = link["href"]
Cria a planilha
df = pd.DataFrame(dados)
df.to_excel("roendo_livros.xlsx", index=False)
print(f"{len(df)} registros salvos em roendo_livros.xlsx")