I was hoping to find an API gateway of it from XHR or JS of website, but I didn`t manage to find anything there, so i decided to scrape data from each page using this code (with the help of CHATGPT), который извлекает данные с каждой страницы и сохраняет их в файл .csv: < /p>
async def scrape_page(session, page):
"""Scrape data from a single page."""
url = BASE_URL + str(page)
html = await fetch_page(session, url, page)
if not html:
logging.error(f"
return [], None # Skip if page fails
soup = BeautifulSoup(html, "html.parser")
table = soup.find("table", {"id": lambda x: x and x.startswith("guid-")})
if not table:
logging.warning(f"
return [], None
titles = [th.text.strip() for th in table.find_all("th")]
rows = table.find_all("tr")[1:] # Skip first row (headers)
data = [[td.text.strip() for td in row.find_all("td")] for row in rows]
print(f"
return data, titles
< /code>
То, с чем я столкнулся, - это то, что слишком много страниц (приблизительно 20 000 страниц с 15 рядами данных на каждой странице), и мне слишком много времени требуется, чтобы соскребить все это. Есть предложения о том, как я мог бы оптимизировать этот процесс?
Подробнее здесь: https://stackoverflow.com/questions/795 ... b-scraping
Мобильная версия