requestor / main.py
navpan2's picture
Upload 4 files
003e243
raw
history blame
1.07 kB
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}