Skip to content

Instantly share code, notes, and snippets.

View gaganmanku96's full-sized avatar

Gagandeep Singh gaganmanku96

  • Gurgaon
View GitHub Profile
@gaganmanku96
gaganmanku96 / selenium_remote_driver_scraping.py
Created May 22, 2022 04:22
Code to scrape data from a test website
def main():
URL = "https://webscraper.io/test-sites/e-commerce/allinone"
driver = get_driver()
driver.get(URL)
driver.implicitly_wait(10)
products = driver.find_elements(By.XPATH, '//div[@class="col-sm-4 col-lg-4 col-md-4"]')
for product in products:
product_title = product.find_element(By.XPATH, './/a[@class="title"]').text
@gaganmanku96
gaganmanku96 / selenium_remote_driver.py
Created May 22, 2022 04:10
Initializing a remote driver of selenium
def get_driver():
time.sleep(3)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--headless")
driver = webdriver.Remote(
command_executor='http://headless_chrome:3000/webdriver',
options=chrome_options,
)
from flask import Flask, requests
from ml_model import Model
model = Model()
app = Flask(__name__)
@app.route('/predict', methods=['POST'])
def predict():
recieved_params = requests.get_json(force=True)
output = model.predict(recieved_params)
def add(first_num: int, second_num: int) -> int:
return first_num + second_num
add("a", "b")
>>ab
>>> var = "Hello"
>>> type(var)
<class 'str'>
>>> var = 28.1
>>> type(var)
<class 'float'>
from typing import Union
def add(first_value: int, second_value: int) -> Union(int, bool):
if first_value == 0:
return False
return first_value + second_value
from typing import Tuple
def add(first_value: int, second_value: int) -> Tuple[int, int]:
print(f"Sum = {first_value+second_value}")
return first_value, second_value
def add(first_value: int, second_value: int) -> int:
return first_value + second value
def add(first_value: int, second_value: int):
pass
import requests
f = {'file': open('img.jpg', 'rb').read()}
URL = 'http://127.0.0.1:5000/predict'
result = requests.post(URL, files=f)
print(result.text)