Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,45 +1,54 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import time
|
| 3 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
|
| 6 |
-
# Function to launch
|
| 7 |
def fiverr_search(query):
|
| 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 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
def send_message(seller_name, question):
|
| 41 |
# Simulating sending a message to the seller on Fiverr
|
| 42 |
-
#
|
| 43 |
response = f"Message to {seller_name}: {question} (Sent successfully)"
|
| 44 |
return response
|
| 45 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import time
|
| 3 |
+
from selenium import webdriver
|
| 4 |
+
from selenium.webdriver.common.by import By
|
| 5 |
+
from selenium.webdriver.chrome.service import Service
|
| 6 |
+
from webdriver_manager.chrome import ChromeDriverManager
|
| 7 |
+
from bs4 import BeautifulSoup
|
| 8 |
import pandas as pd
|
| 9 |
|
| 10 |
+
# Function to launch Selenium and scrape Fiverr for top 10 sellers
|
| 11 |
def fiverr_search(query):
|
| 12 |
+
# Setup for Selenium WebDriver
|
| 13 |
+
options = webdriver.ChromeOptions()
|
| 14 |
+
options.add_argument("--headless") # Run in headless mode
|
| 15 |
+
|
| 16 |
+
# Launch Chrome browser using WebDriver
|
| 17 |
+
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
|
| 18 |
+
|
| 19 |
+
# Go to Fiverr and search for the service
|
| 20 |
+
driver.get("https://www.fiverr.com/")
|
| 21 |
+
time.sleep(2) # Let the page load
|
| 22 |
+
search_box = driver.find_element(By.NAME, "search")
|
| 23 |
+
search_box.send_keys(query)
|
| 24 |
+
search_box.submit()
|
| 25 |
+
time.sleep(3) # Wait for results to load
|
| 26 |
+
|
| 27 |
+
# Parse the page with BeautifulSoup
|
| 28 |
+
soup = BeautifulSoup(driver.page_source, "html.parser")
|
| 29 |
+
|
| 30 |
+
# Extract top 10 sellers
|
| 31 |
+
seller_names = soup.find_all("span", class_="seller-name")
|
| 32 |
+
seller_titles = soup.find_all("div", class_="gig-title")
|
| 33 |
+
prices = soup.find_all("span", class_="price")
|
| 34 |
+
|
| 35 |
+
sellers = []
|
| 36 |
+
for i in range(min(10, len(seller_names))):
|
| 37 |
+
name = seller_names[i].get_text(strip=True)
|
| 38 |
+
title = seller_titles[i].get_text(strip=True)
|
| 39 |
+
price = prices[i].get_text(strip=True)
|
| 40 |
+
sellers.append([name, title, price])
|
| 41 |
+
|
| 42 |
+
# Close the browser
|
| 43 |
+
driver.quit()
|
| 44 |
+
|
| 45 |
+
# Return seller data as a dataframe
|
| 46 |
+
return pd.DataFrame(sellers, columns=["Seller", "Title", "Price"])
|
| 47 |
+
|
| 48 |
+
# Function to send message to sellers (simulated for now)
|
| 49 |
def send_message(seller_name, question):
|
| 50 |
# Simulating sending a message to the seller on Fiverr
|
| 51 |
+
# Real contact would need login session, but this is just for testing.
|
| 52 |
response = f"Message to {seller_name}: {question} (Sent successfully)"
|
| 53 |
return response
|
| 54 |
|