File size: 1,073 Bytes
003e243
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

from fastapi import FastAPI
import time
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')

app = FastAPI()
favicon_path='https://www.iconarchive.com/download/i49313/martin-berube/sport/Soccer.ico'

@app.get("/")
def read_root():
    return {"Hello": "World"}
@app.get("/selenium/")
async def read_item(reqUrl,tag):
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=chrome_options)
    url= reqUrl
    driver.get(url)
    time.sleep(3)
    soup = BeautifulSoup(driver.page_source,'lxml')
    headings = soup.find_all( name= tag)
    a=[]
    for heading in headings:
        a.append(heading.getText())
    driver.quit()
    return {"Hello": a}