京东爬虫,数据转为elasticsearch以及csv文件

本文介绍了如何使用Python的requests、parsel库以及Elasticsearch进行网络请求,从京东搜索结果中抓取商品名称、价格、店铺和链接,并将数据存储到Elasticsearch中以备后续分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import requests
import parsel
import csv
from elasticsearch import Elasticsearch

es = Elasticsearch(["https://localhost:9200"], basic_auth=('elastic', 'hw-FxQTckOuswZ1jRikA'), verify_certs=False,
                   request_timeout=3600)
print(es)
INDEX_NAME = "jd-produict-list"
mappings = {
    "mappings": {

        "properties": {
            "name": {
                "type": "text"
            },
            "price": {
                "type": "text"
            },
            "link": {
                "type": "text",
                "index": "false"
            },
            "shop": {
                "type": "text",
            }
        }

    }
}
res1 = es.options(ignore_status=404).indices.delete(index=INDEX_NAME)
res = es.indices.create(index=INDEX_NAME, body=mappings)
print(res)
url = ("https://api.m.jd.com/?appid=search-pc-java&functionId=pc_search_s_new&client=pc&clientVersion=1.0.0&t"
       "=1713168142494&body=%7B%22keyword%22%3A%22java%22%2C%22pvid%22%3A%22555ce3e0d8264f2d91d2a39ce764254d%22%2C"
       "%22page%22%
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值