-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreelancer_spider.py
37 lines (29 loc) · 1.34 KB
/
freelancer_spider.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
import scrapy
from scrapy.crawler import CrawlerProcess
class FreelanceSpider(scrapy.Spider):
name = "freelancespider"
jobs = []
def __init__(self, skillset='Python', min_price=100, *args, **kwargs):
super(FreelanceSpider, self).__init__(*args, **kwargs)
self.start_urls = [
f'https://www.freelancer.com/jobs/{skillset.lower().replace(" ", "-")}/'
]
self.min_price = min_price
def parse(self, response):
# Extracting each job card on the page
job_cards = response.css("div.JobSearchCard-item-inner")
for job_card in job_cards:
# Extracting title, description, and price of each job
title = job_card.css("a.JobSearchCard-primary-heading-link::text").get()
description = job_card.css("p.JobSearchCard-primary-description::text").get()
price = str(job_card.css("div.JobSearchCard-secondary-price::text").get())
if 'None' in price:
continue
else:
price = price.split()[0].replace('$', '')
if title and description and price:
if self.min_price is None or int(price) >= int(self.min_price):
self.jobs.append([title.strip(), description.strip(), '$'+str(price)])
process = CrawlerProcess()
process.crawl(FreelanceSpider)
process.start()