import streamlit as st import time from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager from bs4 import BeautifulSoup import pandas as pd # Function to launch Selenium and scrape Fiverr for top 10 sellers def fiverr_search(query): # Setup for Selenium WebDriver options = webdriver.ChromeOptions() options.add_argument("--headless") # Run in headless mode # Launch Chrome browser using WebDriver driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) # Go to Fiverr and search for the service driver.get("https://www.fiverr.com/") time.sleep(2) # Let the page load search_box = driver.find_element(By.NAME, "search") search_box.send_keys(query) search_box.submit() time.sleep(3) # Wait for results to load # Parse the page with BeautifulSoup soup = BeautifulSoup(driver.page_source, "html.parser") # Extract top 10 sellers seller_names = soup.find_all("span", class_="seller-name") seller_titles = soup.find_all("div", class_="gig-title") prices = soup.find_all("span", class_="price") sellers = [] for i in range(min(10, len(seller_names))): name = seller_names[i].get_text(strip=True) title = seller_titles[i].get_text(strip=True) price = prices[i].get_text(strip=True) sellers.append([name, title, price]) # Close the browser driver.quit() # Return seller data as a dataframe return pd.DataFrame(sellers, columns=["Seller", "Title", "Price"]) # Function to send message to sellers (simulated for now) def send_message(seller_name, question): # Simulating sending a message to the seller on Fiverr # Real contact would need login session, but this is just for testing. response = f"Message to {seller_name}: {question} (Sent successfully)" return response # Streamlit frontend: User interface for interaction def main(): st.title("Fiverr Service Search Agent") # Ask the user for the service to search query = st.text_input("Enter the service you need (e.g., 'logo design'):") # Ask for a question to send to sellers question = st.text_input("Enter the question to ask sellers (e.g., 'Do you offer express delivery?'):") if st.button("Search Fiverr"): if query and question: st.write(f"Searching Fiverr for: {query}...") results = fiverr_search(query) # Show top 10 sellers st.write("Top 10 Sellers Found:") st.dataframe(results) # Send the same message to all top sellers st.write("Sending message to sellers...") responses = [] for seller in results["Seller"]: response = send_message(seller, question) responses.append(response) # Show responses st.write("Responses from sellers:") for response in responses: st.write(response) else: st.error("Please provide both service and question!") if __name__ == "__main__": main()