Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,8 @@ import requests
|
|
7 |
|
8 |
from fastapi.middleware.cors import CORSMiddleware
|
9 |
|
|
|
|
|
10 |
|
11 |
app = FastAPI()
|
12 |
|
@@ -19,7 +21,26 @@ app.add_middleware(
|
|
19 |
)
|
20 |
|
21 |
|
22 |
-
@app.get("/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
async def read_item(username: str, video_id:str):
|
24 |
# 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"
|
25 |
user_agent = "Googlebot/2.1"
|
|
|
7 |
|
8 |
from fastapi.middleware.cors import CORSMiddleware
|
9 |
|
10 |
+
from bs4 import BeautifulSoup
|
11 |
+
|
12 |
|
13 |
app = FastAPI()
|
14 |
|
|
|
21 |
)
|
22 |
|
23 |
|
24 |
+
@app.get("/google_search")
|
25 |
+
async def google_search(q: str):
|
26 |
+
url = f"https://www.google.com/search?q={url}"
|
27 |
+
texts = ""
|
28 |
+
soup = BeautifulSoup(requests.get(url).content, "html.parser")
|
29 |
+
|
30 |
+
for div in soup.find_all("div")[24:]:
|
31 |
+
if len(div.find_parents("div")) == 8: # Depth 4 means 3 parent divs (0-indexed)
|
32 |
+
# print(div.get_text().strip())
|
33 |
+
href = div.find(href=True, recursive=True)
|
34 |
+
text = div.find(text=True, recursive=False)
|
35 |
+
if href and text:
|
36 |
+
print(text)
|
37 |
+
text = f'[{text}]({href["href"].split("/url?q=")[-1]})'
|
38 |
+
if text != None and text.strip():
|
39 |
+
texts += text + "\n---\n"
|
40 |
+
return {"results":texts}
|
41 |
+
|
42 |
+
|
43 |
+
@app.get("/tiktok_details")
|
44 |
async def read_item(username: str, video_id:str):
|
45 |
# 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"
|
46 |
user_agent = "Googlebot/2.1"
|