21天通关python课程_学习笔记(45):21天通关Python(仅视频课)-导出爬取的数据

爬取易车RAV4的数据

# -*- coding: utf-8 -*-

# Define your item pipelines here

#

# Don't forget to add your pipeline to the ITEM_PIPELINES setting

# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html

import json

class YichespiderPipeline(object):

def __init__(self):

# 初始化要写入的JSON

self.json_file = open('carSpider.json', 'wb+')

self.json_file.write('\n'.encode('UTF-8'))

# 该方法的item就是蜘蛛yield的item对象

def process_item(self, item, spider):

text = json.dumps(dict(item), ensure_ascii=False) + ',\n'

self.json_file.write(text.encode("UTF-8"))

# print('款式:', item['design'])

# print('购买时间:', item['buy_date'])

# print('地址:', item['buy_addr'])

# print('裸车价:', item['real_price'])

# print('指导价:', item['original_price'])

def close_spider(self, spider):

print('-------------------------关闭爬虫-------------------------------------')

self.json_file.seek(-2, 1)

self.json_file.write('\n'.encode("UTF-8"))

self.json_file.close()

# -*- coding: utf-8 -*-

import scrapy

from YicheSpider.items import YichespiderItem

class CarSpiderSpider(scrapy.Spider):

name = 'car_spider'

allowed_domains = ['luochejia.yiche.com']

# 从哪个页面开始爬

# urls = ['http://luochejia.yiche.com/yiqifengtianrav4/price/?page=%s' % i for i in range(1, 62)]

# start_urls = urls

start_urls = ['http://luochejia.yiche.com/yiqifengtianrav4/price/?page=1']

def parse(self, response):

# 每个job_primary元素包含一个工作信息

for car_primary in response.xpath('//div[@class="price-list-box"]'):

item = YichespiderItem()

# 款式

item['design'] = car_primary.xpath('./div[@class="con-box"]/div[@class="tit"]/text()').extract_first()

# 购买时间

item['buy_date'] = car_primary.xpath('./div[@class="con-box"]/p[@class="other"]/text()').extract_first()

# 地址

item['buy_addr'] = car_primary.xpath('./div[@class="con-box"]/p[@class="other"]/text()').extract_first()

# 裸车价

item['real_price'] = car_primary.xpath(

'./div[@class="con-box"]/div[@class="price"]/p[@class="luochejia"]/em/text()').extract_first()

# 指导价

item['original_price'] = car_primary.xpath(

'./div[@class="con-box"]/div[@class="price"]/p[@class="zhidaojia"]/text()').extract_first()

yield item

next_page = response.xpath('//div[@class="pagination mbt20"]/div/a[@class="next-on"]/@href').extract()

# 增加判断

countNum = 0

# 第一页往后一个

if next_page and len(next_page) > 1:

new_link = next_page[1]

print(

'下一页地址:http://luochejia.yiche.com' + new_link + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')

yield scrapy.Request('http://luochejia.yiche.com' + new_link, callback=self.parse)

elif next_page and len(next_page) > 0 and countNum == 0:

new_link = next_page[0]

print(

"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++当前是第一页+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")

print(

'下一页地址:http://luochejia.yiche.com' + new_link + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')

yield scrapy.Request('http://luochejia.yiche.com' + new_link, callback=self.parse)

else:

pass

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你好!要通关 upload-labs 靶场的第 1-21 关,你需要依次完成每个关卡的任务。以下是通关每个关卡的一些提示: 1. Level 1 - 文件上传漏洞:尝试上传一个恶意文件,看看能否绕过上传限制。 2. Level 2 - 文件包含漏洞:尝试利用文件包含漏洞,读取服务器上的敏感文件。 3. Level 3 - XXE漏洞:在上传的 XML 文件中尝试触发外部实体注入。 4. Level 4 - SQL注入漏洞:利用输入点进行 SQL 注入攻击,尝试获取数据库中的敏感信息。 5. Level 5 - SSRF漏洞:尝试利用服务器端请求伪造漏洞,发起内部网络请求。 6. Level 6 - 文件上传漏洞2:绕过上传限制,上传一个恶意文件。 7. Level 7 - 文件包含漏洞2:利用文件包含漏洞,读取服务器上的敏感文件。 8. Level 8 - 反序列化漏洞:尝试触发反序列化漏洞,执行恶意代码。 9. Level 9 - 文件上传漏洞3:绕过上传限制,上传一个恶意文件。 10. Level 10 - 文件包含漏洞3:利用文件包含漏洞,读取服务器上的敏感文件。 11. Level 11 - XXE漏洞2:在上传的 XML 文件中触发外部实体注入。 12. Level 12 - SSRF漏洞2:尝试利用服务器端请求伪造漏洞,发起内部网络请求。 13. Level 13 - 文件上传漏洞4:绕过上传限制,上传一个恶意文件。 14. Level 14 - 文件包含漏洞4:利用文件包含漏洞,读取服务器上的敏感文件。 15. Level 15 - SQL注入漏洞2:利用输入点进行 SQL 注入攻击,尝试获取数据库中的敏感信息。 16. Level 16 - 文件上传漏洞5:绕过上传限制,上传一个恶意文件。 17. Level 17 - 文件包含漏洞5:利用文件包含漏洞,读取服务器上的敏感文件。 18. Level 18 - 反序列化漏洞2:尝试触发反序列化漏洞,执行恶意代码。 19. Level 19 - 文件上传漏洞6:绕过上传限制,上传一个恶意文件。 20. Level 20 - 文件包含漏洞6:利用文件包含漏洞,读取服务器上的敏感文件。 21. Level 21 - XXE漏洞3:在上传的 XML 文件中触发外部实体注入。 请注意,在完成每个关卡时,要仔细阅读相关提示和代码,理解漏洞的原理,并尝试不同的方法来解决问题。祝你顺利通关

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值