Python帮你买口罩 获取某东的部分口罩数据

口罩数据抓取

概述

最近武汉的疫情让全国都关注起来这个城市,小编就在这个城市求学图片,最近经常收到朋友的不定期问候,甚是感动图片。面对疫情,目前我们能做的就是不信谣不传谣,尽量做好自身卫生,保护好自己,因此各种口罩开始脱销(N95),很多人不得不去网上购买口罩。这里对京东商品列表中的口罩一栏进行部分数据获取,用于帮助大家选择。祝大家都健健康康,开开心心的。若想获取代码或数据请私信小编图片。

实现过程及结果

就是普通的爬虫技术,用到了JS渲染数据而已。BeautifulSoup解析数据。最后把数据存储到本地的Excel表格中以便后期使用。

从图3可以看到销量比较好的是鲜行者和绿德(数据所得,与小编无关)

Python帮你买口罩 获取某东的部分口罩数据

Python帮你买口罩 获取某东的部分口罩数据
Python帮你买口罩 获取某东的部分口罩数据
部分代码如下


 list = soup.find(class_='gl-warp clearfix').find_all(class_='gl-item')

    for item in list:
        item_product_id = item.find(class_='gl-i-wrap j-sku-item').get('data-sku')
        if len(item.find(class_='p-name').find_all('span')) == 2:
            item_product_name_be = item.find(class_='p-name').find('em').text.strip('span').split("              ")
            item_product_name = item_product_name_be[len(item_product_name_be) - 1]
        else:
            item_product_name = item.find(class_='p-name').find('em').text
        item_product_price = item.find(class_='J_price').text.replace('¥', '')

        if len(item.find(class_='p-shop')) != 0:
            item_stroe_name = item.find(class_='p-shop').find('a').get('title')
        else:
            item_stroe_name = "~"

        item_product_info_all = item.find(class_='p-icons J-pro-icons').text
        item_product_link1 = item.find(class_='p-img').find('a').get('href')
        item_product_link = item.find(class_='comment').text
        print(item_product_link)

猜你喜欢

转载自blog.51cto.com/15069472/2577348