Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# Import libraries and packages for the project
|
| 2 |
import requests
|
| 3 |
import gradio as gr
|
| 4 |
from bs4 import BeautifulSoup
|
|
@@ -6,7 +5,7 @@ from bs4 import BeautifulSoup
|
|
| 6 |
print('- Finish importing packages')
|
| 7 |
|
| 8 |
# Function to search LinkedIn profiles
|
| 9 |
-
def search_linkedin_profiles(username, password
|
| 10 |
# Initialize session
|
| 11 |
session = requests.Session()
|
| 12 |
|
|
@@ -23,29 +22,9 @@ def search_linkedin_profiles(username, password, keyword):
|
|
| 23 |
# Check if login was successful
|
| 24 |
if response.ok:
|
| 25 |
print('- Finish Task 1: Login to LinkedIn')
|
| 26 |
-
|
| 27 |
-
# Now perform the search using the provided keyword
|
| 28 |
-
search_url = f'https://www.linkedin.com/search/results/people/?keywords={keyword}&origin=SWITCH_SEARCH_VERTICAL'
|
| 29 |
-
search_response = session.get(search_url)
|
| 30 |
-
|
| 31 |
-
# Check if the search request was successful
|
| 32 |
-
if search_response.ok:
|
| 33 |
-
print('- Finish Task 2: Search completed successfully')
|
| 34 |
-
|
| 35 |
-
# Uncomment the below lines to parse profiles instead
|
| 36 |
-
soup = BeautifulSoup(search_response.text, 'html.parser')
|
| 37 |
-
profiles = []
|
| 38 |
-
# Example parsing logic (modify according to the actual HTML structure)
|
| 39 |
-
for profile in soup.find_all('div', class_='search-result__info'):
|
| 40 |
-
name = profile.find('span', class_='actor-name').get_text(strip=True)
|
| 41 |
-
title = profile.find('p', class_='subline-level-1').get_text(strip=True)
|
| 42 |
-
profiles.append({'name': name, 'title': title})
|
| 43 |
-
|
| 44 |
-
return {'success': True, 'profiles': profiles} # Return parsed profiles
|
| 45 |
-
else:
|
| 46 |
-
return {'success': False, 'error': 'Search request failed. Status code: {}'.format(search_response.status_code)}
|
| 47 |
else:
|
| 48 |
-
return {
|
| 49 |
|
| 50 |
# Gradio Interface
|
| 51 |
iface = gr.Interface(
|
|
@@ -53,11 +32,10 @@ iface = gr.Interface(
|
|
| 53 |
inputs=[
|
| 54 |
gr.Textbox(label="Username", placeholder="Enter your LinkedIn username"),
|
| 55 |
gr.Textbox(label="Password", placeholder="Enter your LinkedIn password", type="password"),
|
| 56 |
-
gr.Textbox(label="Keyword", placeholder="Enter a keyword to search for profiles")
|
| 57 |
],
|
| 58 |
-
outputs=gr.JSON(label="
|
| 59 |
-
title="LinkedIn
|
| 60 |
-
description="
|
| 61 |
)
|
| 62 |
|
| 63 |
# Launch the Gradio app
|
|
|
|
|
|
|
| 1 |
import requests
|
| 2 |
import gradio as gr
|
| 3 |
from bs4 import BeautifulSoup
|
|
|
|
| 5 |
print('- Finish importing packages')
|
| 6 |
|
| 7 |
# Function to search LinkedIn profiles
|
| 8 |
+
def search_linkedin_profiles(username, password):
|
| 9 |
# Initialize session
|
| 10 |
session = requests.Session()
|
| 11 |
|
|
|
|
| 22 |
# Check if login was successful
|
| 23 |
if response.ok:
|
| 24 |
print('- Finish Task 1: Login to LinkedIn')
|
| 25 |
+
return {"response": response.text} # Correctly format the response as a dictionary
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
else:
|
| 27 |
+
return {"error": "Login failed"} # Provide error feedback
|
| 28 |
|
| 29 |
# Gradio Interface
|
| 30 |
iface = gr.Interface(
|
|
|
|
| 32 |
inputs=[
|
| 33 |
gr.Textbox(label="Username", placeholder="Enter your LinkedIn username"),
|
| 34 |
gr.Textbox(label="Password", placeholder="Enter your LinkedIn password", type="password"),
|
|
|
|
| 35 |
],
|
| 36 |
+
outputs=gr.JSON(label="Search Result"), # Change the label for clarity
|
| 37 |
+
title="LinkedIn",
|
| 38 |
+
description="linkedin scraaper test"
|
| 39 |
)
|
| 40 |
|
| 41 |
# Launch the Gradio app
|