-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_data.py
32 lines (26 loc) · 876 Bytes
/
get_data.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
import asyncio
import csv
import json
from douyin_tiktok_scraper.scraper import Scraper
api = Scraper()
async def hybrid_parsing(url: str) -> dict:
# Hybrid parsing(Douyin/TikTok URL)
result = await api.hybrid_parsing(url)
print(f"The hybrid parsing result:\n {result}")
return result
def read_url_from_csv(filename: str) -> str:
with open(filename, 'r') as file:
csv_reader = csv.reader(file)
# Assuming the URL is in the first column of the CSV
for row in csv_reader:
return row[0]
return None
def save_data_to_json(filename: str, data: dict):
with open(filename, 'w') as file:
json.dump(data, file, indent=4)
url = read_url_from_csv("urls.csv")
if url:
response = asyncio.run(hybrid_parsing(url))
save_data_to_json("data.json", response)
else:
print("No URL found in the CSV file.")