Ejemplo 1: rastreador web de Python
import scrapy
class BlogSpider(scrapy.Spider):
name = 'blogspider'
start_urls = ['https://blog.scrapinghub.com']
def parse(self, response):
for title in response.css('.post-header>h2'):
yield {'title': title.css('a ::text').get()}
for next_page in response.css('a.next-posts-link'):
yield response.follow(next_page, self.parse)
Ejemplo 2: proyecto de creación de scrapy
scrapy startproject projectname
Ejemplo 3: cómo ejecutar scrapy dentro de un nm
import scrapy
from scrapy.crawler import CrawlerProcess
class MySpider(scrapy.Spider):
# Your spider definition
...
process = CrawlerProcess(settings={
"FEEDS": {
"items.json": {"format": "json"},
},
})
process.crawl(MySpider)
process.start() # the script will block here until the crawling is finished
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)