From 9a524a6c080b12306a89c6a7ad0895d652156ca4 Mon Sep 17 00:00:00 2001 From: banchui <1204335622@qq.com> Date: Sun, 14 Mar 2021 21:45:00 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E7=AC=AC=E5=8D=81?= =?UTF-8?q?=E5=91=A8=E7=AC=AC=E4=BA=8C=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\215\201\345\221\250\344\275\234\344\270\232/\347\254\254\345\215\201\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/.keep" diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\215\201\345\221\250\344\275\234\344\270\232/\347\254\254\345\215\201\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\215\201\345\221\250\344\275\234\344\270\232/\347\254\254\345\215\201\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 00000000..e69de29b -- Gitee From 0f4eb0ef4b4b4f236cbf4f4b97391e1e5cc95c70 Mon Sep 17 00:00:00 2001 From: banchui <1204335622@qq.com> Date: Sun, 14 Mar 2021 21:45:49 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=AC=AC=E5=8D=81=E5=91=A8=E7=AC=AC?= =?UTF-8?q?=E4=BA=8C=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jd_search.py" | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 "\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\215\201\345\221\250\344\275\234\344\270\232/\347\254\254\345\215\201\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/jd_search.py" diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\215\201\345\221\250\344\275\234\344\270\232/\347\254\254\345\215\201\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/jd_search.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\215\201\345\221\250\344\275\234\344\270\232/\347\254\254\345\215\201\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/jd_search.py" new file mode 100644 index 00000000..6b96fa87 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\215\201\345\221\250\344\275\234\344\270\232/\347\254\254\345\215\201\345\221\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/jd_search.py" @@ -0,0 +1,51 @@ +import json +from bs4 import BeautifulSoup +from jd_crawler_scrapy.items import JdCrawlerScrapyItem + + +import scrapy + +class JDSearch(scrapy.Spider): + name = "jd_search" + + def start_requests(self): + for keyword in ["鼠标", "键盘", "电脑", "耳机"]: + for page_num in range(1,11): + url = f"https://search.jd.com/Search?keyword={keyword}&pag={page_num}" + yield scrapy.FormRequest( + url = url, + method = 'GET', + # formdata=data, + callback=self.parse_search + + + ) + def parse_search(self, response): + + soup = BeautifulSoup(response.text, "lxml") + item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") + for item in item_array: + sku_id = item.attrs["data-sku"] + img = item.select("img[data-img='1']") + price = item.select("div[class='p-price']") + title = item.select("div[class='p=name p-name-type-2']") + shop = item.select("div[class='p-shop']") + icons = item.select("div[class='p-icons']") + + img = img[0].attrs['data-lazy-img'] if img else "" + price = price[0].strong.i.text if price else "" + title = title[0].text.strip() if title else "" + shop = shop[0].a.attrs['title'] if shop[0].text.strip() else "" + icons = json.dumps([tag_ele.text for tag_ele in icons[0].select('i')]) if icons else '[]' + + + item = JdCrawlerScrapyItem() + item["img"] = img + item["sku_id"] = sku_id + item["price"] = price + item["title"] = title + item["shop"] = shop + item["icons"] = icons + + yield item + -- Gitee From 47f3dbf329a10f8be204ac8992bb8e30543dfdd6 Mon Sep 17 00:00:00 2001 From: banchui <1204335622@qq.com> Date: Sun, 14 Mar 2021 21:46:04 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E7=AC=AC=E5=8D=81?= =?UTF-8?q?=E5=91=A8=E7=AC=AC=E4=B8=89=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\215\201\345\221\250\344\275\234\344\270\232/\347\254\254\345\215\201\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/.keep" diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\215\201\345\221\250\344\275\234\344\270\232/\347\254\254\345\215\201\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\271\264\350\275\273\344\272\272\344\270\215\350\256\262\345\220\276\345\276\267/\347\254\254\345\215\201\345\221\250\344\275\234\344\270\232/\347\254\254\345\215\201\345\221\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 00000000..e69de29b -- Gitee