50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
import re
|
|
from urllib.parse import urljoin
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
from config import BASE_URL, CITY
|
|
|
|
|
|
def parse_girl_links(html_content):
|
|
soup = BeautifulSoup(html_content, "lxml")
|
|
links = []
|
|
|
|
for card in soup.select(".list-girls-item-mob[data-girlid]"):
|
|
girl_id = card.get("data-girlid")
|
|
|
|
a = card.select_one(".list-girls-img-mob a[href]")
|
|
if not a:
|
|
a = card.select_one(".list-girls-right-info > a[href]")
|
|
if not a:
|
|
continue
|
|
|
|
href = a.get("href")
|
|
if not re.match(r"^/{}/\d+/?$".format(CITY), href):
|
|
continue
|
|
|
|
links.append({"id": girl_id, "url": urljoin(BASE_URL, href)})
|
|
|
|
return links
|
|
|
|
|
|
def parse_telegram_href(soup):
|
|
link = soup.select_one(".girl-indi-mess.dm-mess-100 a#TELEGRAM_CLICK_MOB[href]")
|
|
return link["href"] if link else None
|
|
|
|
|
|
async def parse_single_girl(session, link):
|
|
async with session.get(link["url"]) as response:
|
|
html_content = await response.text()
|
|
|
|
soup = BeautifulSoup(html_content, "lxml")
|
|
print(f"Профиль: {link['url']}")
|
|
|
|
telegram_href = parse_telegram_href(soup)
|
|
if not telegram_href:
|
|
print(" тг не указан")
|
|
return None
|
|
|
|
print(f" тг: {telegram_href}")
|
|
return {"profile_url": link["url"], "telegram": telegram_href}
|