chburhan64 commited on
Commit
ccc826f
·
verified ·
1 Parent(s): f41ca5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -35
app.py CHANGED
@@ -1,45 +1,54 @@
1
  import streamlit as st
2
  import time
3
- from playwright.sync_api import sync_playwright
 
 
 
 
4
  import pandas as pd
5
 
6
- # Function to launch Playwright and scrape Fiverr for top 10 sellers
7
  def fiverr_search(query):
8
- # Start Playwright browser
9
- with sync_playwright() as p:
10
- browser = p.chromium.launch(headless=True)
11
- page = browser.new_page()
12
-
13
- # Go to Fiverr
14
- page.goto("https://www.fiverr.com/")
15
-
16
- # Search for the given query
17
- page.fill("input[name='search'] ", query)
18
- page.click("button[data-testid='search-btn']")
19
- time.sleep(3) # Allow search results to load
20
-
21
- # Extract top 10 sellers
22
- seller_names = page.query_selector_all(".gig-card-layout .seller-name")
23
- seller_titles = page.query_selector_all(".gig-card-layout .gig-title")
24
- prices = page.query_selector_all(".gig-card-layout .price")
25
-
26
- # Data collection
27
- sellers = []
28
- for i in range(min(10, len(seller_names))):
29
- name = seller_names[i].inner_text()
30
- title = seller_titles[i].inner_text()
31
- price = prices[i].inner_text().strip()
32
- sellers.append([name, title, price])
33
-
34
- browser.close()
35
-
36
- # Return seller data as a dataframe
37
- return pd.DataFrame(sellers, columns=["Seller", "Title", "Price"])
38
-
39
- # Function to contact the seller
 
 
 
 
 
40
  def send_message(seller_name, question):
41
  # Simulating sending a message to the seller on Fiverr
42
- # For now, it's just logging the action (Real contact would need login session)
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