-
Notifications
You must be signed in to change notification settings - Fork 84
/
run.py
37 lines (28 loc) · 1.63 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
This example run script shows how to run the Aliexpress.com scraper defined in ./aliexpress.py
It scrapes product data and product search and saves it to ./results/
To run this script set the env variable $SCRAPFLY_KEY with your scrapfly API key:
$ export $SCRAPFLY_KEY="your key from https://scrapfly.io/dashboard"
"""
import asyncio
import json
from pathlib import Path
import aliexpress
output = Path(__file__).parent / "results"
output.mkdir(exist_ok=True)
async def run():
# enable scrapfly cache for basic use
# aliexpress.BASE_CONFIG["cache"] = True # session can't be combined with cache
aliexpress.BASE_CONFIG["debug"] = True
print("running Aliexpress scrape and saving results to ./results directory")
# note: aliexpress search has a bug where wholsepages show no results without `SearchText` parameter for some reason
url = "https://www.aliexpress.com/w/wholesale-drills.html?catId=0&SearchText=drills"
search_results = await aliexpress.scrape_search(url, max_pages=2)
output.joinpath("search.json", ).write_text(json.dumps(search_results, indent=2, ensure_ascii=False), encoding="utf-8")
url = "https://www.aliexpress.com/item/1005006717259012.html"
product_results = await aliexpress.scrape_product(url)
output.joinpath("product.json").write_text(json.dumps(product_results, indent=2, ensure_ascii=False), encoding="utf-8")
review_results = await aliexpress.scrape_product_reviews("1005006717259012", max_scrape_pages=3)
output.joinpath("reviews.json").write_text(json.dumps(review_results, indent=2, ensure_ascii=False), encoding="utf-8")
if __name__ == "__main__":
asyncio.run(run())