当前位置:AIGC资讯 > 数据采集 > 正文

头歌实训答案:Scrapy爬虫之网站图片爬取

Scrapy爬虫之网站图片爬取

第1关:爬取网站实训图片的链接

# -*- coding: utf-8 -*-
import scrapy


class EduspiderSpider(scrapy.Spider):
   name = 'eduSpider'
   allowed_domains = ['127.0.0.1']
   start_urls = ['http://127.0.0.1:8080/imgs/']

   def parse(self, response):
       #********** Begin **********#
        with open('images.txt','w') as f:
           img = response.xpath("//div[@class='box']/div/a/img/@src")
           f.write("{}\n"

更新时间 2023-11-08