安装

具体请自行百度

依赖库

Scrapy 教程(一)-安装与入门

 

网上说pip安装会内分泌失调,我试了下还行吧,不过也遇到几个问题

Scrapy 教程(一)-安装与入门

解决方法

pip install -I cryptography

 

Scrapy 教程(一)-安装与入门

解决方法

pip install -U pyopenssl

安装成功

Scrapy 教程(一)-安装与入门

 

 

离线下载地址  https://pypi.org/project/Scrapy/#files

 

实战入门

import scrapy

class MovieItem(scrapy.Item):
    # define the fields for your item here like:
    name = scrapy.Field()

class MeijuSpider(scrapy.Spider):
    name = "meiju"
    allowed_domains = ["meijutt.com"]
    start_urls = ['http://www.meijutt.com/new100.html']

    def parse(self, response):
        movies = response.xpath('//ul[@class="top-list  fn-clear"]/li')
        for each_movie in movies:
            item = MovieItem()
            item['name'] = each_movie.xpath('./h5/a/@title').extract()[0]
            yield item

命令行运行

scrapy runspider test.py -o test1.json

自动生成 test.json 文件,并存入爬取内容。

 

这是最简单的代码和运行方式。

 

相关文章:

  • 2022-12-23
  • 2021-10-02
  • 2021-12-23
  • 2021-09-28
  • 2021-09-17
猜你喜欢
  • 2021-11-23
  • 2021-10-02
  • 2021-08-12
  • 2021-11-23
  • 2021-09-13
  • 2021-10-02
相关资源
相似解决方案