Last active
October 7, 2022 01:24
-
-
Save rogersdepelle/44d1812de611ceee7b11c7f0decf8c81 to your computer and use it in GitHub Desktop.
Scraper for get clients from meucatalogodigital.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import math | |
import requests | |
from bs4 import BeautifulSoup | |
HEADERS = { | |
"accept": "*/*", | |
"user-agent": "Dalvik/2.1.0 (Linux; U; Android 9; Redmi 7 MIUI/V11.0.9.0.PFLRUXM)", | |
"x-requested-with": "XMLHttpRequest", | |
} | |
def get_orders(session, page): | |
params = { | |
"p": page, | |
} | |
response = session.get("https://painel.meucatalogodigital.com/pedidos/", params=params, headers=HEADERS) | |
return BeautifulSoup(response.text, "html.parser") | |
data = { | |
"redirect": "/", | |
"email": "EMAIL", | |
"senha": "PASSWORD", | |
"dominio": "DOMINIO", | |
} | |
session = requests.Session() | |
session.post("https://painel.meucatalogodigital.com/acesso/", headers=HEADERS, data=data) | |
soup = get_orders(session, 1) | |
orders = int(soup.select_one(".resultados").text.split()[0]) | |
pages = math.ceil(orders / 16) + 1 | |
phones = [] | |
with open("contacts.csv", mode="w") as contacts_file: | |
contacts_writer = csv.writer(contacts_file) | |
contacts_writer.writerow(["nome", "telefone"]) | |
for page in range(2, pages): | |
for order in soup.select(".list-pedidos li:not(:first-child)"): | |
name = order.select_one("div:nth-child(2)").text.strip() | |
phone = order.select_one("a").text.strip() | |
if phone not in phones: | |
phones.append(phone) | |
contacts_writer.writerow([name, phone]) | |
soup = get_orders(session, page) | |
print(f"{len(phones)} phones from {orders} orders") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment