Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ from fastapi import FastAPI, Header, Query
|
|
4 |
|
5 |
import html2text
|
6 |
import requests
|
|
|
7 |
|
8 |
from fastapi.middleware.cors import CORSMiddleware
|
9 |
|
@@ -47,8 +48,8 @@ async def google_search(q: str, delimiter: str = "\n---\n", sites: Annotated[lis
|
|
47 |
|
48 |
@app.get("/tiktok_details")
|
49 |
async def read_item(username: str, video_id:str):
|
50 |
-
|
51 |
-
user_agent = "Googlebot/2.1"
|
52 |
# if "https:" in link_detail:
|
53 |
# url = link_detail
|
54 |
# elif link_detail[0] == "/":
|
@@ -58,7 +59,10 @@ async def read_item(username: str, video_id:str):
|
|
58 |
|
59 |
url = f"https://tiktok.com/@{username}/video/{video_id}"
|
60 |
|
61 |
-
|
|
|
|
|
|
|
62 |
text_maker = html2text.HTML2Text()
|
63 |
text_maker.ignore_links = True
|
64 |
text_maker.ignore_images = True
|
|
|
4 |
|
5 |
import html2text
|
6 |
import requests
|
7 |
+
import httpx
|
8 |
|
9 |
from fastapi.middleware.cors import CORSMiddleware
|
10 |
|
|
|
48 |
|
49 |
@app.get("/tiktok_details")
|
50 |
async def read_item(username: str, video_id:str):
|
51 |
+
user_agent = "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/W.X.Y.Z Safari/537.36"
|
52 |
+
# user_agent = "Googlebot/2.1"
|
53 |
# if "https:" in link_detail:
|
54 |
# url = link_detail
|
55 |
# elif link_detail[0] == "/":
|
|
|
59 |
|
60 |
url = f"https://tiktok.com/@{username}/video/{video_id}"
|
61 |
|
62 |
+
async with httpx.AsyncClient() as client:
|
63 |
+
res = await client.get(url, headers=headers)
|
64 |
+
|
65 |
+
# res = requests.get(url, headers={"user-agent":user_agent})
|
66 |
text_maker = html2text.HTML2Text()
|
67 |
text_maker.ignore_links = True
|
68 |
text_maker.ignore_images = True
|