Update app.py
Browse files
app.py
CHANGED
|
@@ -194,60 +194,43 @@ def create_interface(name, scrape_function):
|
|
| 194 |
output_file = f"{name.lower()}_scraped_data.csv"
|
| 195 |
|
| 196 |
def clean_text(text):
|
| 197 |
-
return
|
| 198 |
|
| 199 |
with open(output_file, 'w', newline='', encoding='utf-8') as f:
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
writer = csv.DictWriter(f, fieldnames=fieldnames)
|
| 209 |
-
writer.writeheader()
|
| 210 |
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
}
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
if i < len(educations):
|
| 237 |
-
edu = educations[i]
|
| 238 |
-
clean_row[f'education_{i+1}_school'] = clean_text(edu.get('title', ''))
|
| 239 |
-
clean_row[f'education_{i+1}_degree'] = clean_text(edu.get('subtitle', ''))
|
| 240 |
-
clean_row[f'education_{i+1}_date'] = clean_text(edu.get('caption', ''))
|
| 241 |
-
else:
|
| 242 |
-
clean_row[f'education_{i+1}_school'] = ''
|
| 243 |
-
clean_row[f'education_{i+1}_degree'] = ''
|
| 244 |
-
clean_row[f'education_{i+1}_date'] = ''
|
| 245 |
-
|
| 246 |
-
clean_row['languages'] = ', '.join([lang.get('title', '') for lang in row.get('languages', [])])
|
| 247 |
-
clean_row['skills'] = ', '.join([skill.get('title', '') for skill in row.get('skills', [])[:10]])
|
| 248 |
-
|
| 249 |
-
writer.writerow(clean_row)
|
| 250 |
-
|
| 251 |
return output_file
|
| 252 |
|
| 253 |
preview_button.click(lambda x: preview_csv(x, scrape_function), inputs=input_file, outputs=preview)
|
|
|
|
| 194 |
output_file = f"{name.lower()}_scraped_data.csv"
|
| 195 |
|
| 196 |
def clean_text(text):
|
| 197 |
+
return str(text).replace('\n', ' ').strip()
|
| 198 |
|
| 199 |
with open(output_file, 'w', newline='', encoding='utf-8') as f:
|
| 200 |
+
writer = csv.writer(f)
|
| 201 |
+
for profile in data:
|
| 202 |
+
writer.writerow(["Profile Information"])
|
| 203 |
+
writer.writerow([f"Name: {clean_text(profile.get('fullName', ''))}"])
|
| 204 |
+
writer.writerow([f"Headline: {clean_text(profile.get('headline', ''))}"])
|
| 205 |
+
writer.writerow([f"Location: {clean_text(profile.get('addressWithCountry', ''))}"])
|
| 206 |
+
writer.writerow([f"Connections: {profile.get('connections', '')}"])
|
| 207 |
+
writer.writerow([f"About: {clean_text(profile.get('about', ''))}"])
|
|
|
|
|
|
|
| 208 |
|
| 209 |
+
writer.writerow(["Experiences"])
|
| 210 |
+
for exp in profile.get('experiences', [])[:5]: # Limit to top 5 experiences
|
| 211 |
+
writer.writerow([f"Title: {clean_text(exp.get('title', ''))}"])
|
| 212 |
+
writer.writerow([f"Company: {clean_text(exp.get('subtitle', ''))}"])
|
| 213 |
+
writer.writerow([f"Duration: {clean_text(exp.get('caption', ''))}"])
|
| 214 |
+
writer.writerow([]) # Empty row for readability
|
| 215 |
+
|
| 216 |
+
writer.writerow(["Education"])
|
| 217 |
+
for edu in profile.get('educations', [])[:3]: # Limit to top 3 educations
|
| 218 |
+
writer.writerow([f"School: {clean_text(edu.get('title', ''))}"])
|
| 219 |
+
writer.writerow([f"Degree: {clean_text(edu.get('subtitle', ''))}"])
|
| 220 |
+
writer.writerow([f"Years: {clean_text(edu.get('caption', ''))}"])
|
| 221 |
+
writer.writerow([]) # Empty row for readability
|
| 222 |
+
|
| 223 |
+
writer.writerow(["Skills"])
|
| 224 |
+
skills = [clean_text(skill.get('title', '')) for skill in profile.get('skills', [])[:10]]
|
| 225 |
+
writer.writerow([", ".join(skills)])
|
| 226 |
+
|
| 227 |
+
writer.writerow(["Languages"])
|
| 228 |
+
languages = [clean_text(lang.get('title', '')) for lang in profile.get('languages', [])]
|
| 229 |
+
writer.writerow([", ".join(languages)])
|
| 230 |
+
|
| 231 |
+
writer.writerow([]) # Empty row between profiles
|
| 232 |
+
writer.writerow([]) # Empty row between profiles
|
| 233 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
return output_file
|
| 235 |
|
| 236 |
preview_button.click(lambda x: preview_csv(x, scrape_function), inputs=input_file, outputs=preview)
|