美文网首页编程地带
京东商品爬取

京东商品爬取

作者: MA木易YA | 来源:发表于2018-11-05 17:02 被阅读0次

这次的练习主要是对京东的ipad商品页面进行爬取,主页如下:

image.png

items.py

对名字、商铺、价格和营销方式进行抓取

    name = scrapy.Field()
    shop = scrapy.Field()
    icon = scrapy.Field()
    price = scrapy.Field()

jd_spider.py

此处对url是自己观察规律进行构造的,发现url只有page进行了改变,并且是以2的间隔增长

class JdSpiderSpider(scrapy.Spider):
    name = 'jd_spider'
    allowed_domains = ['www.jd.com']
    start_urls = ['https://search.jd.com/Search?keyword=ipad&enc=utf-8&page={}'.format(str(i) for i in range(1,101, 2 ))]


    def parse(self, response):
        lists = response.xpath('//li[@class="gl-item"]/div')
        for list in lists:
            item = JingdongItem()
            item['name'] = list.xpath('.//div[@class="p-name p-name-type-2"]/a/em/text()').extract_first()
            item['shop'] = list.xpath('.//div[@class="p-shop"]/span/a/text()').extract_first()
            item['icon'] = list.xpath('.//div[@class="p-icons"]/i[@class="goods-icons J-picon-tips J-picon-fix"]/text()').extract_first()
            item['price'] = list.xpath('.//div[@class="p-price"]/strong/i/text()').extract_first()
            yield item
  •    其他爬虫代码可参考github

相关文章

  • 京东商品爬取

    这次的练习主要是对京东的ipad商品页面进行爬取,主页如下: items.py 对名字、商铺、价格和营销方式进行抓...

  • 案例集锦

    案例一: 京东商品页面的爬取 案例二:亚马逊商品页面的爬取 由于amazon禁止python访问,要把header...

  • 网络爬虫实战(5个案例)

    案例1:京东商品页面的爬取 商品链接 案例2:亚马逊商品页面的爬取 商品链接 案例3:百度360关键词提交 搜索引...

  • 爬取京东商品实例

  • requests库网络爬取实战

    @[toc] 实例1:京东商品页面的爬取 实例2:亚马逊商品页面的爬取 需要伪造请求头 实例3:百度/360搜索关...

  • 入门级爬虫(2)

    requests库入门实操我的个人博客 京东商品页面爬取 亚马逊商品页面的爬取 百度/360搜索关键字提交 IP地...

  • 1.python爬虫实例

    1.京东商品页面的爬取 2.亚马逊商品页面的爬取 用headers字段,让代码模拟浏览器向亚马逊服务器提供请求。 ...

  • 爬取京东商品评论

    爬取京东商品评论 #--*--coding:utf-8--*-- import requests import j...

  • 爬取京东商品信息

    功能 从京东商城的商品列表页面解析出商品详情页链接,进而解析出商品名称,编号,店铺,品类等信息 代码片段及说明 模...

  • 爬取京东商品信息

    利用 BeautifulSoup + Requests 爬取京东商品信息并保存在Excel中 一、查看网页信息 打...

网友评论

    本文标题:京东商品爬取

    本文链接:https://www.haomeiwen.com/subject/rwgsxqtx.html