Update app.py
Browse files
app.py
CHANGED
@@ -66,17 +66,16 @@ def calculate_similarity(name1, name2):
|
|
66 |
|
67 |
|
68 |
def fetch_linkedin_links(query, api_key, applicant_name):
|
69 |
-
"""Fetches LinkedIn profile links using
|
70 |
try:
|
71 |
url = "https://api.brightdata.com/request"
|
72 |
-
|
73 |
|
74 |
payload = {
|
75 |
-
"url":
|
76 |
-
"zone": "residential", # Replace with your actual zone if needed
|
77 |
-
"format": "raw",
|
78 |
"method": "GET",
|
79 |
-
"country": "us",
|
|
|
80 |
"data_format": "html"
|
81 |
}
|
82 |
|
@@ -85,14 +84,16 @@ def fetch_linkedin_links(query, api_key, applicant_name):
|
|
85 |
"Content-Type": "application/json"
|
86 |
}
|
87 |
|
88 |
-
response = requests.post(url,
|
89 |
response.raise_for_status()
|
90 |
|
91 |
html = response.text
|
|
|
|
|
92 |
linkedin_regex = r'https://(?:[a-z]{2,3}\.)?linkedin\.com/in/[a-zA-Z0-9\-_/]+'
|
|
|
93 |
|
94 |
-
|
95 |
-
for link in links:
|
96 |
profile_name = get_name_from_url(link)
|
97 |
if profile_name:
|
98 |
similarity = calculate_similarity(applicant_name, profile_name)
|
@@ -101,8 +102,7 @@ def fetch_linkedin_links(query, api_key, applicant_name):
|
|
101 |
return None
|
102 |
except Exception as e:
|
103 |
st.error(f"Error fetching link for query '{query}': {e}")
|
104 |
-
return None
|
105 |
-
|
106 |
|
107 |
def process_file(file, api_key):
|
108 |
"""Processes the uploaded Excel file to fetch LinkedIn profile links."""
|
|
|
66 |
|
67 |
|
68 |
def fetch_linkedin_links(query, api_key, applicant_name):
|
69 |
+
"""Fetches LinkedIn profile links using BrightData SERP scraping API."""
|
70 |
try:
|
71 |
url = "https://api.brightdata.com/request"
|
72 |
+
google_url = f"https://www.google.com/search?q={requests.utils.quote(query)}"
|
73 |
|
74 |
payload = {
|
75 |
+
"url": google_url,
|
|
|
|
|
76 |
"method": "GET",
|
77 |
+
"country": "us", # Optional: your target country
|
78 |
+
"format": "raw",
|
79 |
"data_format": "html"
|
80 |
}
|
81 |
|
|
|
84 |
"Content-Type": "application/json"
|
85 |
}
|
86 |
|
87 |
+
response = requests.post(url, headers=headers, json=payload)
|
88 |
response.raise_for_status()
|
89 |
|
90 |
html = response.text
|
91 |
+
|
92 |
+
# Match standard LinkedIn profile URLs
|
93 |
linkedin_regex = r'https://(?:[a-z]{2,3}\.)?linkedin\.com/in/[a-zA-Z0-9\-_/]+'
|
94 |
+
matches = re.findall(linkedin_regex, html)
|
95 |
|
96 |
+
for link in matches:
|
|
|
97 |
profile_name = get_name_from_url(link)
|
98 |
if profile_name:
|
99 |
similarity = calculate_similarity(applicant_name, profile_name)
|
|
|
102 |
return None
|
103 |
except Exception as e:
|
104 |
st.error(f"Error fetching link for query '{query}': {e}")
|
105 |
+
return None
|
|
|
106 |
|
107 |
def process_file(file, api_key):
|
108 |
"""Processes the uploaded Excel file to fetch LinkedIn profile links."""
|