-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDescription.py
32 lines (23 loc) · 1013 Bytes
/
Description.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
import scrapy
from scrapy.crawler import CrawlerProcess
class DescriptionSpider(scrapy.Spider):
name = "description"
def start_requests(self):
url = "https://www.datacamp.com/courses/tech:python"
yield scrapy.Request(url=url, callback=self.parse)
def parse(self, response):
c_link = response.css("div.course-block>a::attr(href)").getall()
for url in c_link:
yield response.follow(url=url, callback=self.parse1)
def parse1(self, response):
c_name = response.css('h1.header-hero__title::text').getall()
c_description = response.css('p.course__description::text').getall()
with open("Courses.txt", "a") as f:
for name in c_name:
f.write(name+"\t:\n")
for des in c_description:
f.write(des)
f.write('\n\n\n\n')
process = CrawlerProcess()
process.crawl(DescriptionSpider)
process.start()