-
Notifications
You must be signed in to change notification settings - Fork 81
/
run.py
64 lines (52 loc) · 2.37 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
This example run script shows how to run the Linkedin.com scraper defined in ./linkedin.py
It scrapes product data and saves it to ./results/
To run this script set the env variable $SCRAPFLY_KEY with your scrapfly API key:
$ export $SCRAPFLY_KEY="your key from https://scrapfly.io/dashboard"
"""
import asyncio
import json
from pathlib import Path
import linkedin
output = Path(__file__).parent / "results"
output.mkdir(exist_ok=True)
async def run():
# enable scrapfly cache
linkedin.BASE_CONFIG["cache"] = False
linkedin.BASE_CONFIG["debug"] = True
print("running Linkedin scrape and saving results to ./results directory")
profile_data = await linkedin.scrape_profile(
urls=[
"https://www.linkedin.com/in/williamhgates"
]
)
with open(output.joinpath("profile.json"), "w", encoding="utf-8") as file:
json.dump(profile_data, file, indent=2, ensure_ascii=False)
company_data = await linkedin.scrape_company(
urls=[
"https://linkedin.com/company/microsoft",
"https://linkedin.com/company/google",
"https://linkedin.com/company/apple"
]
)
with open(output.joinpath("company.json"), "w", encoding="utf-8") as file:
json.dump(company_data, file, indent=2, ensure_ascii=False)
job_search_data = await linkedin.scrape_job_search(
# it include other search parameters, refer to the search pages on browser for more details
keyword="Python Developer",
location="United States",
max_pages=3
)
with open(output.joinpath("job_search.json"), "w", encoding="utf-8") as file:
json.dump(job_search_data, file, indent=2, ensure_ascii=False)
job_data = await linkedin.scrape_jobs(
urls=[
"https://www.linkedin.com/jobs/view/data-center-engineering-operations-engineer-hyd-infinity-dceo-at-amazon-web-services-aws-4017265505",
"https://www.linkedin.com/jobs/view/content-strategist-google-cloud-content-strategy-and-experience-at-google-4015776107",
"https://www.linkedin.com/jobs/view/sr-content-marketing-manager-brand-protection-brand-protection-at-amazon-4007942181"
]
)
with open(output.joinpath("jobs.json"), "w", encoding="utf-8") as file:
json.dump(job_data, file, indent=2, ensure_ascii=False)
if __name__ == "__main__":
asyncio.run(run())