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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-2/9-2-001.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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-2/9-2-001.py" new file mode 100644 index 0000000000000000000000000000000000000000..715467e488c9022bd54112d48f126d0ec0db2da9 --- /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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-2/9-2-001.py" @@ -0,0 +1,18 @@ +from bs4 import BeautifulSoup +import lxml +def jd_search_parse(html): + html=html.replace('\r\n', "").replace("\n", "").replace("\t", "") + soup=BeautifulSoup(html,"lxml") + item=soup.select("li[data-sku='6039832']")[0] + # print(item) + # print(item.text) + print(item.previous_sibling) + print(item.next_sibling.next_sibling) + + + +if __name__=="__main__": + with open("jd_search.html","r",encoding="utf-8") as f: + html=f.read() + + jd_search_parse(html) \ No newline at end of file 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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-2/CSS-BeautifulSoup\345\205\203\347\264\240\345\256\232\344\275\215-9-2noteyun -0309\350\241\245.md" "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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-2/CSS-BeautifulSoup\345\205\203\347\264\240\345\256\232\344\275\215-9-2noteyun -0309\350\241\245.md" new file mode 100644 index 0000000000000000000000000000000000000000..e5b75e91ba6c6f6880e3ba5ad765e1eaa8dcac6e --- /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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-2/CSS-BeautifulSoup\345\205\203\347\264\240\345\256\232\344\275\215-9-2noteyun -0309\350\241\245.md" @@ -0,0 +1,251 @@ +9-2noteyun + +# css-selector + +> 尽量避免解析路径中包含位置信息 + +> chrome页面中内置了Jquery环境, 用$符号来表示 + +## 直接定位元素 + +- 通过id进行定位 + + ```python + $("#id值") + ``` + +- 通过class进行定位 + + ```python + $(".class值") + ``` + +- **通过属性名进行定位** + + ```python + $("标签名[属性名='属性值']") + + $("ul[class='gl-warp clearfix']") + ``` + +## 获取兄弟节点 + +- 获取当前节点的下一个节点 + + - dom提供的接口, 不属于css-selector语法 + + ```python + tmp = $("li[data-sku='6039832']")[0] + tmp.nextElementSibling#获取兄弟节点;右边一个商品 + ``` + + - 通过css-selector(不建议) + + ```python + $("ul[class='gl-warp clearfix'] li:first-child + li") + ``` + +- 获取当前节点的上一个节点 + + - dom提供的接口, 不属于css-selector语法 + + ```python + tmp = $("li[data-sku='2136538']")[0] + tmp.previousElementSibling #获取兄弟节点;左边一个商品 + ``` + +## 获取父子节点 + +- 获取父节点 + + - dom提供的接口, 不属于css-selector语法 + + ```python + tmp.parentElement + ``` + +- 获取子节点 + + - 获取所有子节点 + + - **遍历**所有符合条件的元素 + + ```python + $("ul[class='gl-warp clearfix'] div[class='gl-i-wrap']") + + ``` + + $("ul[class='gl-warp clearfix'] li[class='gl-item']")[0] + + ``` + + - dom提供的接口, 不属于css-selector语法 + + ​```python + $("ul[class='gl-warp clearfix']")[0].children + ``` + + ![image-20210309165518896](C:\Users\yunqin\AppData\Roaming\Typora\typora-user-images\image-20210309165518896.png) + + - 获取第一个子节点 + + ```python + :fist-child + $("ul[class='gl-warp clearfix'] li:first-child")[0] + ``` + + - 获取最后一个子节点 + + ```python + :last-child + $("ul[class='gl-warp clearfix'] li:last-child")[0] + ``` + + - 获取第N个子节点 + + ```python + #:nth-child(索引) 获取第五个 + $("ul[class='gl-warp clearfix'] li:nth-child(5)")[0] + ``` + + ![image-20210309170300638](C:\Users\yunqin\AppData\Roaming\Typora\typora-user-images\image-20210309170300638.png) + +# 模糊匹配 + +- 匹配开头 + + `^` + + ```python + # 匹配data-sku属性值为2开头的元素 + $("li[data-sku^='2']") + ``` + + ![image-20210309173231429](C:\Users\yunqin\AppData\Roaming\Typora\typora-user-images\image-20210309173231429.png) + +- 匹配结尾 + + `$` + + ```python + $("li[data-sku$='2']") + ``` + +- 匹配子集 + + `*` + + ```python + $("li[data-sku*='2']") + ``` + + ![image-20210309173254084](C:\Users\yunqin\AppData\Roaming\Typora\typora-user-images\image-20210309173254084.png) + +- 获取文本值 + + ```python + $("li[data-sku='6039832'] div[class='p-name p-name-type-2'] em")[0].innerText + ``` + + ![image-20210309173518534](C:\Users\yunqin\AppData\Roaming\Typora\typora-user-images\image-20210309173518534.png) + + ![image-20210309174512487](C:\Users\yunqin\AppData\Roaming\Typora\typora-user-images\image-20210309174512487.png) + + + +- 获取属性值 + + ```python + $("ul[class='gl-warp clearfix'] li")[0].getAttribute("data-sku") + ``` + + ![image-20210309174838554](C:\Users\yunqin\AppData\Roaming\Typora\typora-user-images\image-20210309174838554.png) + +# BeautifulSoup + +- 安装 + + ```python + pip install bs4 + pip install lxml + ``` + +- 使用BeautifulSoup + + ```python + from bs4 import BeautifulSoup + + + def jd_search_parse(html): + soup = BeautifulSoup(html, "lxml") + item = soup.select("li[data-sku='6039832']")[0] + ``` + +- 直接定位元素 + + 略 + +- 去除空白字符 + + ```python + html = html.replace('\r\n', "").replace("\n", "").replace("\t", "") + ``` + + ![image-20210309181256218](C:\Users\yunqin\AppData\Roaming\Typora\typora-user-images\image-20210309181256218.png) + +- 获取兄弟节点 + + - 获取上一个节点 + + ```python + tmp_ele.previous_sibling + ``` + + - 获取下一个节点 + + ```python + tmp_ele.next_sibling + ``` + +- 获取父子节点 + + - 获取父节点 + + ```python + tmp_ele.parent + ``` + + - 获取子节点 + + ```python + tmp_ele.children + ``` + +- 模糊匹配 + + 略 + +- 获取文本值 + + ```python + content = tmp_ele.text.strip() + ``` + +- 获取属性值 + + ```python + value = tmp_ele.attrs["data-sku"] + ``` + + ![image-20210310092223685](C:\Users\yunqin\AppData\Roaming\Typora\typora-user-images\image-20210310092223685.png) + + ![image-20210310092449257](C:\Users\yunqin\AppData\Roaming\Typora\typora-user-images\image-20210310092449257.png) + + ![image-20210310093322969](C:\Users\yunqin\AppData\Roaming\Typora\typora-user-images\image-20210310093322969.png) + + debug:50分钟之后; + +# 课后作业 + +- 练习css-selector +- 练习用beautifulsoup进行页面解析 \ No newline at end of file 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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-2/jd_search.html" "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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-2/jd_search.html" new file mode 100644 index 0000000000000000000000000000000000000000..2c3965e9a69712b78a3efc6914872baed4f3c8f9 --- /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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-2/jd_search.html" @@ -0,0 +1,6611 @@ + + + + + + + + + + + + + + + + + + + + + +鼠标 - 商品搜索 - 京东 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+
+
+
+
+ +
+
+ +
+
+ +
+
+
+
+ + 0 + 我的购物车 +
+
+
+
无线鼠标|键盘|鼠标垫|鼠标有线|游戏鼠标|罗技鼠标|机械键盘|蓝牙鼠标|键盘鼠标|罗技|鼠标自营|雷蛇鼠标|静音鼠标|雷蛇
+ +
+ + +
+ + +
+
+
+
+ +
+ > +
+ "鼠标" +
+
+
+
+ +
+ +
+ +
+
+
品牌:
+
+
    +
  • 所有品牌
  • +
  • A
  • +
  • B
  • +
  • C
  • +
  • D
  • +
  • E
  • +
  • F
  • +
  • G
  • +
  • H
  • +
  • I
  • +
  • J
  • +
  • K
  • +
  • L
  • +
  • M
  • +
  • N
  • +
  • O
  • +
  • P
  • +
  • Q
  • +
  • R
  • +
  • S
  • +
  • T
  • +
  • U
  • +
  • W
  • +
  • X
  • +
  • Y
  • +
  • Z
  • +
+
+
+ +
+
已选条件:
    +
    + 确定 + 取消 +
    +
    +
    + 更多 + 多选 +
    +
    +
    +
    +
    +
    外设产品:
    +
    +
    + +
    +
    + 确定 + 取消 +
    +
    +
    + 更多 + +
    +
    +
    + +
    +
    +
    电脑整机:
    +
    +
    + +
    +
    + 确定 + 取消 +
    +
    +
    + 更多 + +
    +
    +
    + +
    +
    +
    连接方式:
    +
    +
    + +
    +
    + 确定 + 取消 +
    +
    +
    + + 多选 +
    +
    +
    +
    +
    +
    适用场景:
    +
    +
    + +
    +
    + 确定 + 取消 +
    +
    +
    + + +
    +
    +
    +
    +
    +
    高级选项:
    + +
    + + + + + + + + + + + +
    +
    +
    +
    +
    +
    + + + + +
    + + + +
    + +
    <上一页1234567...下一页>100页  到第确定
    +
    +
    +
    +
    +
    + +

    商品精选

    +
    +
      +
    +
    +
    + + +
    +
    + +
    + + +
    +
    +
    +
    +
    + +
    商品精选
    +
    +
    +
    +
    + +
    +
    +

    猜你喜欢

    加载中,请稍候...
    +
    + +
    +
    +
      +
    1. + 品类齐全,轻松购物 +
    2. +
    3. + 多仓直发,极速配送 +
    4. +
    5. + 正品行货,精致服务 +
    6. +
    7. + 天天低价,畅选无忧 +
    8. +
    +
    +
    +
    +
    +
    +
    购物指南
    +
    + 购物流程 +
    +
    + 会员介绍 +
    +
    + 生活旅行/团购 +
    +
    + 常见问题 +
    +
    + 大家电 +
    +
    + 联系客服 +
    +
    +
    +
    配送方式
    +
    + 上门自提 +
    +
    + 211限时达 +
    +
    + 配送服务查询 +
    +
    + 配送费收取标准 +
    +
    + 海外配送 +
    +
    +
    +
    支付方式
    +
    + 货到付款 +
    +
    + 在线支付 +
    +
    + 分期付款 +
    +
    + 公司转账 +
    +
    +
    +
    售后服务
    +
    + 售后政策 +
    +
    + 价格保护 +
    +
    + 退款说明 +
    +
    + 返修/退换货 +
    +
    + 取消订单 +
    +
    +
    +
    特色服务
    +
    + 夺宝岛 +
    +
    + DIY装机 +
    +
    + 延保服务 +
    +
    + 京东E卡 +
    +
    + 京东通信 +
    +
    + 京鱼座智能 +
    +
    + +
    +
    +
    +
    + + +

    京东会员

    京东会员 0
    成功加入购物车!
    购物车
    成功加入购物车!
    我的消息 0
    成功加入购物车!
    + + + + + + \ No newline at end of file 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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/001.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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/001.py" new file mode 100644 index 0000000000000000000000000000000000000000..bc34bb6b1e2eb099bb6a19a675081ffead8b0432 --- /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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/001.py" @@ -0,0 +1,5 @@ +import sys +# print(sys.path)#打印路径列表 +# ['E:\\PycharmProjects\\train002_1231\\second-python-bootcamp\\第二期训练营\\5班\\5班_云\\第9周0222--0228\\9-3\\jd_crawler', 'E:\\PycharmProjects\\train002_1231\\second-python-bootcamp', 'E:\\PycharmProjects\\train002_1231\\second-python-bootcamp\\第二期训练营\\5班\\5班_云\\第9周0222--0228\\9-3\\jd_crawler', 'E:\\PycharmProjects\\train002_1231\\second-python-bootcamp\\第二期训练营\\5班\\5班_云\\第9周0222--0228\\9-3', 'D:\\bsoft\\ananaconda\\python37.zip', 'D:\\bsoft\\ananaconda\\DLLs', 'D:\\bsoft\\ananaconda\\lib', 'D:\\bsoft\\ananaconda', 'D:\\bsoft\\ananaconda\\lib\\site-packages', 'D:\\bsoft\\ananaconda\\lib\\site-packages\\win32', 'D:\\bsoft\\ananaconda\\lib\\site-packages\\win32\\lib', 'D:\\bsoft\\ananaconda\\lib\\site-packages\\Pythonwin'] +# sys.path.append(r"H:\PyCharmProjects\tutorials_2")#不灵活 +print("001",__name__) \ No newline at end of file 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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/__pycache__/settings.cpython-37.pyc" "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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/__pycache__/settings.cpython-37.pyc" new file mode 100644 index 0000000000000000000000000000000000000000..66896cfba1c0cab53199d3159e8d98988c45f309 Binary files /dev/null and "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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/__pycache__/settings.cpython-37.pyc" differ 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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/jd_parser/__pycache__/search.cpython-37.pyc" "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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/jd_parser/__pycache__/search.cpython-37.pyc" new file mode 100644 index 0000000000000000000000000000000000000000..eb5c5ac342a83faad7ca1baca2e833f29f725c6f Binary files /dev/null and "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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/jd_parser/__pycache__/search.cpython-37.pyc" differ 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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/jd_parser/detail.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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/jd_parser/detail.py" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/jd_parser/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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/jd_parser/search.py" new file mode 100644 index 0000000000000000000000000000000000000000..07e63d8ee07ac9140dd59808162e9b3de624da77 --- /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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/jd_parser/search.py" @@ -0,0 +1,40 @@ +from bs4 import BeautifulSoup +import json + +def parse_jd_item(html):#解析器 + result = []#列表,收集,解析的结果 + + soup = BeautifulSoup(html, "lxml") + print(soup) + item_array = soup.select("ul[class='gl-warp clearfix'] li[class='gl-item']") + # $("ul[class='gl-warp clearfix'] li[class='gl-item']") + for item in item_array: + try: + 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']") + # print(img) + + + 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 '[]' + + result.append((sku_id, img, price, title, shop, icons))#收集结果 + except Exception as e: + print(e.args) + return result + # return result + + +if __name__ == "__main__": + with open(r"..\\test\\search.html", "r", encoding="utf-8") as f: + + html = f.read() + result = parse_jd_item(html) + print(result) \ No newline at end of file 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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/main.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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/main.py" new file mode 100644 index 0000000000000000000000000000000000000000..35123b587f0705a67b4ba12b376ad0e1c2acdb39 --- /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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/main.py" @@ -0,0 +1,54 @@ +import random +import pymysql +import requests +from jd_crawler.jd_parser.search import parse_jd_item +from jd_crawler.settings import MYSQL_CONF, HEADERS + + +def saver(item_array):#保存到sql数据库 + """ + 持久化爬取结果 + :param item_array: + :return: + """ + cursor = mysql_con.cursor()#每次建立一个游标 + SQL = """INSERT INTO jd_search(sku_id,img,price, title, shop, icons) + VALUES ( %s,%s, %s, %s, %s, %s)""" + cursor.executemany(SQL, item_array) + mysql_con.commit()#提交、入库 + cursor.close()#关闭游标 + +def donwloader(task):#下载器 + """ + 下载器 + 请求目标网址的组件 + :param task: + :return: + """ + url = "https://search.jd.com/Search" + params = { + "keyword": task #关键词的列表 + } + res = requests.get(url=url, params=params, headers=HEADERS, timeout=10, + # proxies={"https": f"https:144.255.48.62","http": f"http:144.255.48.62"} + ) + return res + + +def main(task_array):#main函数,调度器 + """ + 爬虫任务的调度 + :return: + """ + for task in task_array: + result = donwloader(task)#下载器 + item_array = parse_jd_item(result.text)#解析器 + print("GET ITEMS", item_array)#打印语句,检查执行的正确与否,及其过程 + saver(item_array) + + +if __name__ == "__main__":#入口 + # 用来代替生产者 + mysql_con = pymysql.connect(**MYSQL_CONF) + task_array = ["鼠标", "键盘", "显卡", "耳机"] + main(task_array) \ No newline at end of file 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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/settings.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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/settings.py" new file mode 100644 index 0000000000000000000000000000000000000000..d260ebbe81a4237833c331fedfe1fe8d34055935 --- /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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/settings.py" @@ -0,0 +1,14 @@ +# 设置文件 +# 请求头 +HEADERS = { + "user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36", + # "upgrade-insecure-requests": "1" +} + +# 配置 +MYSQL_CONF = { + "host": "127.0.0.1", + "user": "root", + "password": "123456", + "db": "py_class" +} \ No newline at end of file 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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/shubiao_jd01.html" "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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/shubiao_jd01.html" new file mode 100644 index 0000000000000000000000000000000000000000..2d96bb96193cd8135bec536583e5ad654c0cfb8a --- /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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/shubiao_jd01.html" @@ -0,0 +1,5475 @@ + + + + + + + + + + + + + + + + + + + + + +鼠标 - 商品搜索 - 京东 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    +
    +
    +
    +
    + +
    +
    + +
    +
    + +
    +
    +
    +
    + + 0 + 我的购物车 +
    +
    +
    +
    无线鼠标|键盘|鼠标垫|游戏鼠标|鼠标有线|罗技鼠标|机械键盘|蓝牙鼠标|键盘鼠标|罗技|鼠标自营|雷蛇鼠标|静音鼠标|雷蛇
    + +
    + + +
    + + +
    +
    +
    +
    + +
    + > +
    + "鼠标" +
    +
    +
    +
    + +
    + +
    + +
    +
    +
    品牌:
    +
    +
      +
    • 所有品牌
    • +
    • A
    • +
    • B
    • +
    • C
    • +
    • D
    • +
    • E
    • +
    • F
    • +
    • G
    • +
    • H
    • +
    • I
    • +
    • J
    • +
    • K
    • +
    • L
    • +
    • M
    • +
    • N
    • +
    • O
    • +
    • P
    • +
    • Q
    • +
    • R
    • +
    • S
    • +
    • T
    • +
    • U
    • +
    • W
    • +
    • X
    • +
    • Y
    • +
    • Z
    • +
    +
    +
    + +
    +
    已选条件:
      +
      + 确定 + 取消 +
      +
      +
      + 更多 + 多选 +
      +
      +
      +
      +
      +
      外设产品:
      +
      +
      + +
      +
      + 确定 + 取消 +
      +
      +
      + 更多 + +
      +
      +
      + +
      +
      +
      电脑整机:
      +
      +
      + +
      +
      + 确定 + 取消 +
      +
      +
      + 更多 + +
      +
      +
      + +
      +
      +
      连接方式:
      +
      +
      + +
      +
      + 确定 + 取消 +
      +
      +
      + + 多选 +
      +
      +
      +
      +
      +
      适用场景:
      +
      +
      + +
      +
      + 确定 + 取消 +
      +
      +
      + + +
      +
      +
      +
      +
      +
      高级选项:
      + +
      + + + + + + + + + + + +
      +
      +
      +
      +
      +
      + + + + +
      + + + +
      +
      正在加载中,请稍后~~
      +
      <上一页1234567...下一页>100页  到第确定
      +
      +
      +
      +
      +
      + +

      商品精选

      +
      +
        +
      +
      +
      + + +
      +
      + +
      + + +
      +
      +
      +
      +
      + +
      商品精选
      +
      +
      +
      +
      + +
      +
      +
      +
      + +
      +
      +
        +
      1. + 品类齐全,轻松购物 +
      2. +
      3. + 多仓直发,极速配送 +
      4. +
      5. + 正品行货,精致服务 +
      6. +
      7. + 天天低价,畅选无忧 +
      8. +
      +
      +
      +
      +
      +
      +
      购物指南
      +
      + 购物流程 +
      +
      + 会员介绍 +
      +
      + 生活旅行/团购 +
      +
      + 常见问题 +
      +
      + 大家电 +
      +
      + 联系客服 +
      +
      +
      +
      配送方式
      +
      + 上门自提 +
      +
      + 211限时达 +
      +
      + 配送服务查询 +
      +
      + 配送费收取标准 +
      +
      + 海外配送 +
      +
      +
      +
      支付方式
      +
      + 货到付款 +
      +
      + 在线支付 +
      +
      + 分期付款 +
      +
      + 公司转账 +
      +
      +
      +
      售后服务
      +
      + 售后政策 +
      +
      + 价格保护 +
      +
      + 退款说明 +
      +
      + 返修/退换货 +
      +
      + 取消订单 +
      +
      +
      +
      特色服务
      +
      + 夺宝岛 +
      +
      + DIY装机 +
      +
      + 延保服务 +
      +
      + 京东E卡 +
      +
      + 京东通信 +
      +
      + 京鱼座智能 +
      +
      + +
      +
      +
      +
      + + +

      京东会员

      京东会员 0
      成功加入购物车!
      购物车
      成功加入购物车!
      我的消息 0
      成功加入购物车!
      + + + + + + \ No newline at end of file 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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/test/parser_test.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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/test/parser_test.py" new file mode 100644 index 0000000000000000000000000000000000000000..84c9c64a6f1df2230f47255a49d2d3b8a9d253d1 --- /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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/test/parser_test.py" @@ -0,0 +1,6 @@ +# from jd_crawler.jd_parser import search +# +# with open(r"..\\test\\search.html", "r", encoding="utf-8") as f: +# html = f.read() +# result = parse_jd_item(html) +# print(result) \ No newline at end of file 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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/test/search.html" "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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/test/search.html" new file mode 100644 index 0000000000000000000000000000000000000000..0f67859bf30f108ca01618bdfc3a29b171484be0 --- /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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_crawler/test/search.html" @@ -0,0 +1,6615 @@ + + + + + + + + + + + + + + + + + + + + +鼠标 - 商品搜索 - 京东 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      +
      + + + +
      +
      +
      +
      +
      + +
      +
      + +
      + + +
      +
      +
      +
      + + + 我的购物车 +
      +
      +
      +
      + +
      +
      +
      +
      + +
      + + +
      + + +
      +
      +
      +
      + +
      + > +
      + "鼠标" +
      +
      +
      +
      + +
      + +
      + +
      +
      +
      品牌:
      +
      +
        +
      • 所有品牌
      • +
      • A
      • +
      • B
      • +
      • C
      • +
      • D
      • +
      • E
      • +
      • F
      • +
      • G
      • +
      • H
      • +
      • I
      • +
      • J
      • +
      • K
      • +
      • L
      • +
      • M
      • +
      • N
      • +
      • O
      • +
      • P
      • +
      • Q
      • +
      • R
      • +
      • S
      • +
      • T
      • +
      • U
      • +
      • W
      • +
      • X
      • +
      • Y
      • +
      • Z
      • +
      +
      +
      + +
      +
      已选条件:
        +
        + 确定 + 取消 +
        +
        +
        + 更多 + 多选 +
        +
        +
        +
        +
        +
        外设产品:
        +
        +
        + +
        +
        + 确定 + 取消 +
        +
        +
        + 更多 + +
        +
        +
        + +
        +
        +
        电脑整机:
        +
        +
        + +
        +
        + 确定 + 取消 +
        +
        +
        + 更多 + +
        +
        +
        + +
        +
        +
        连接方式:
        +
        +
        + +
        +
        + 确定 + 取消 +
        +
        +
        + 更多 + 多选 +
        +
        +
        +
        +
        +
        适用场景:
        +
        +
        + +
        +
        + 确定 + 取消 +
        +
        +
        + 更多 + 多选 +
        +
        +
        +
        +
        +
        高级选项:
        + +
        + + + + + + + + + + + + + + + +
        +
        +
        +
        +
        +
        + +
        +
        + +
        + + + + + +
        +
        +
        +
        + - +
        +
        +
        + + 清空 + 确定 +
        +
        +
        + + 1/100 + + < + > +
        +
        69万+件商品
        + +
        +
        +
        +
        配送至
        +
        +
        +
        北京
        + +
        +
        +
        +
        +
        +
        +
        + + +
        +
        + + +
        + + + +
        +
        正在加载中,请稍后~~
        +
        +
        +
        +
        +
        +
        + +

        商品精选

        +
        +
          +
        +
        +
        +

        精品推荐

        + +
        +
        + +
        + + +
        +
        +
        +
        +
        + +
        商品精选
        +
        +
        +
        +
        + +
        +
        +
        +
        + +
        +
        +
          +
        1. + 品类齐全,轻松购物 +
        2. +
        3. + 多仓直发,极速配送 +
        4. +
        5. + 正品行货,精致服务 +
        6. +
        7. + 天天低价,畅选无忧 +
        8. +
        +
        +
        +
        +
        +
        +
        购物指南
        +
        + 购物流程 +
        +
        + 会员介绍 +
        +
        + 生活旅行/团购 +
        +
        + 常见问题 +
        +
        + 大家电 +
        +
        + 联系客服 +
        +
        +
        +
        配送方式
        +
        + 上门自提 +
        +
        + 211限时达 +
        +
        + 配送服务查询 +
        +
        + 配送费收取标准 +
        +
        + 海外配送 +
        +
        +
        +
        支付方式
        +
        + 货到付款 +
        +
        + 在线支付 +
        +
        + 分期付款 +
        +
        + 公司转账 +
        +
        +
        +
        售后服务
        +
        + 售后政策 +
        +
        + 价格保护 +
        +
        + 退款说明 +
        +
        + 返修/退换货 +
        +
        + 取消订单 +
        +
        +
        +
        特色服务
        +
        + 夺宝岛 +
        +
        + DIY装机 +
        +
        + 延保服务 +
        +
        + 京东E卡 +
        +
        + 京东通信 +
        +
        + 京鱼座智能 +
        +
        + +
        +
        +
        +
        + + +
        + + + + + 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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_search.html" "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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_search.html" new file mode 100644 index 0000000000000000000000000000000000000000..2c3965e9a69712b78a3efc6914872baed4f3c8f9 --- /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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/jd_search.html" @@ -0,0 +1,6611 @@ + + + + + + + + + + + + + + + + + + + + + +鼠标 - 商品搜索 - 京东 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        +
        + + + +
        +
        +
        +
        +
        + +
        +
        + +
        +
        + +
        +
        +
        +
        + + 0 + 我的购物车 +
        +
        +
        +
        无线鼠标|键盘|鼠标垫|鼠标有线|游戏鼠标|罗技鼠标|机械键盘|蓝牙鼠标|键盘鼠标|罗技|鼠标自营|雷蛇鼠标|静音鼠标|雷蛇
        + +
        + + +
        + + +
        +
        +
        +
        + +
        + > +
        + "鼠标" +
        +
        +
        +
        + +
        + +
        + +
        +
        +
        品牌:
        +
        +
          +
        • 所有品牌
        • +
        • A
        • +
        • B
        • +
        • C
        • +
        • D
        • +
        • E
        • +
        • F
        • +
        • G
        • +
        • H
        • +
        • I
        • +
        • J
        • +
        • K
        • +
        • L
        • +
        • M
        • +
        • N
        • +
        • O
        • +
        • P
        • +
        • Q
        • +
        • R
        • +
        • S
        • +
        • T
        • +
        • U
        • +
        • W
        • +
        • X
        • +
        • Y
        • +
        • Z
        • +
        +
        +
        + +
        +
        已选条件:
          +
          + 确定 + 取消 +
          +
          +
          + 更多 + 多选 +
          +
          +
          +
          +
          +
          外设产品:
          +
          +
          + +
          +
          + 确定 + 取消 +
          +
          +
          + 更多 + +
          +
          +
          + +
          +
          +
          电脑整机:
          +
          +
          + +
          +
          + 确定 + 取消 +
          +
          +
          + 更多 + +
          +
          +
          + +
          +
          +
          连接方式:
          +
          +
          + +
          +
          + 确定 + 取消 +
          +
          +
          + + 多选 +
          +
          +
          +
          +
          +
          适用场景:
          +
          +
          + +
          +
          + 确定 + 取消 +
          +
          +
          + + +
          +
          +
          +
          +
          +
          高级选项:
          + +
          + + + + + + + + + + + +
          +
          +
          +
          +
          +
          + + + + +
          + + + +
          + +
          <上一页1234567...下一页>100页  到第确定
          +
          +
          +
          +
          +
          + +

          商品精选

          +
          +
            +
          +
          +
          + + +
          +
          + +
          + + +
          +
          +
          +
          +
          + +
          商品精选
          +
          +
          +
          +
          + +
          +
          +

          猜你喜欢

          加载中,请稍候...
          +
          + +
          +
          +
            +
          1. + 品类齐全,轻松购物 +
          2. +
          3. + 多仓直发,极速配送 +
          4. +
          5. + 正品行货,精致服务 +
          6. +
          7. + 天天低价,畅选无忧 +
          8. +
          +
          +
          +
          +
          +
          +
          购物指南
          +
          + 购物流程 +
          +
          + 会员介绍 +
          +
          + 生活旅行/团购 +
          +
          + 常见问题 +
          +
          + 大家电 +
          +
          + 联系客服 +
          +
          +
          +
          配送方式
          +
          + 上门自提 +
          +
          + 211限时达 +
          +
          + 配送服务查询 +
          +
          + 配送费收取标准 +
          +
          + 海外配送 +
          +
          +
          +
          支付方式
          +
          + 货到付款 +
          +
          + 在线支付 +
          +
          + 分期付款 +
          +
          + 公司转账 +
          +
          +
          +
          售后服务
          +
          + 售后政策 +
          +
          + 价格保护 +
          +
          + 退款说明 +
          +
          + 返修/退换货 +
          +
          + 取消订单 +
          +
          +
          +
          特色服务
          +
          + 夺宝岛 +
          +
          + DIY装机 +
          +
          + 延保服务 +
          +
          + 京东E卡 +
          +
          + 京东通信 +
          +
          + 京鱼座智能 +
          +
          + +
          +
          +
          +
          + + +

          京东会员

          京东会员 0
          成功加入购物车!
          购物车
          成功加入购物车!
          我的消息 0
          成功加入购物车!
          + + + + + + \ No newline at end of file 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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/\347\254\254\344\270\200\344\270\252\347\210\254\350\231\253\351\241\271\347\233\256-9-3noteyun-0310\350\241\245-.md" "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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/\347\254\254\344\270\200\344\270\252\347\210\254\350\231\253\351\241\271\347\233\256-9-3noteyun-0310\350\241\245-.md" new file mode 100644 index 0000000000000000000000000000000000000000..81848acb4b2a03460112b49187defa70b92a3a19 --- /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_\344\272\221/\347\254\2549\345\221\2500222--0228/9-3/\347\254\254\344\270\200\344\270\252\347\210\254\350\231\253\351\241\271\347\233\256-9-3noteyun-0310\350\241\245-.md" @@ -0,0 +1,85 @@ +9-3noteyun- + +# 一个小又全的爬虫项目 + +- 任务生成者 + + 生成爬虫任务的组件, 最大的作用就是建立生产消费者模型, 将生产者和消费者剥离, 可以达到程序暂停重启的功能. + +- 配置文件 + + 当前爬虫项目的基础配置信息, 目的就是统一化配置, 避免重复修改. + +- 主函数/调度器 + + 以逻辑控制流协同各个组件, 完成爬取工作, 具有一定的调度功能 + +- 下载器 + + 用来和目标服务器进行交互, 获取数据的组件 + +- 解析器 + + 用来解析非结构化的页面内容, 获取想要的数据. + +- 存储器 + + 用来持久化解析后的数据 + + - 数据库 + - 存为本地文件, 比较推荐的格式为json, 结构严谨的可以保存为csv + +# 课后作业 + +- 搭建第一个爬虫项目 +- 为当前爬虫项目添加代理 +- 扩展: 将当前项目改造成多线程 +- 扩展2: 将当前项目改造成多进程 +- 扩展3: 通过aiohttp, aiomysql将项目改造成协程. + +# 第8、9周答疑 + +**上周优秀学员** + +https://docs.qq.com/sheet/DTUpURGx2akN3eW1j + +## 8-1作业 + +![img](https://docimg2.docs.qq.com/image/sBQuFj2a610V_-eCnylD5g?w=474&h=137) + +优秀作业 + +[第八周第一节](https://gitee.com/mayugu/second-python-bootcamp/blob/master/第二期训练营/2班/2班_chaos/第八周_第一节/Mysql(四).md) + +第八周第 2 节作业 + +![img](https://docimg2.docs.qq.com/image/f0dlTUOYvf0YB6FSwk4_BQ?w=476&h=163) + +优秀作业 + +[第八周第二节](https://gitee.com/mayugu/second-python-bootcamp/blob/master/第二期训练营/2班/2班_chaos/第八周_第二节/Mysql(五).md) + +## 8-3作业 + +![img](https://docimg2.docs.qq.com/image/0NRGOkmgEEkxhrRf2JWwAg?w=621&h=170) + +## 9-1作业 + +![img](https://docimg6.docs.qq.com/image/VNjNY9pxW2BG-V7n0JMHkw?w=665&h=254) + +## 9-2作业 + +![img](https://docimg7.docs.qq.com/image/lLIogjEZCBB4YGRwfbUkDA?w=344&h=128) + +## 9-3作业 + +![img](https://docimg3.docs.qq.com/image/e5Ky-nFwLXlpg-soABMWPg?w=448&h=226) + +pyquery学习:https://www.cnblogs.com/progor/p/8536444.html + +## 加餐时间 + +我是如何利用技术赚到第一个 1000 元 + +在快手、头条、抖音,搬运小视频;2017年; + 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_\344\272\221/\347\254\2549\345\221\2500222--0228/jd_search.html" "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_\344\272\221/\347\254\2549\345\221\2500222--0228/jd_search.html" new file mode 100644 index 0000000000000000000000000000000000000000..2c3965e9a69712b78a3efc6914872baed4f3c8f9 --- /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_\344\272\221/\347\254\2549\345\221\2500222--0228/jd_search.html" @@ -0,0 +1,6611 @@ + + + + + + + + + + + + + + + + + + + + + +鼠标 - 商品搜索 - 京东 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          +
          + + + +
          +
          +
          +
          +
          + +
          +
          + +
          +
          + +
          +
          +
          +
          + + 0 + 我的购物车 +
          +
          +
          +
          无线鼠标|键盘|鼠标垫|鼠标有线|游戏鼠标|罗技鼠标|机械键盘|蓝牙鼠标|键盘鼠标|罗技|鼠标自营|雷蛇鼠标|静音鼠标|雷蛇
          + +
          + + +
          + + +
          +
          +
          +
          + +
          + > +
          + "鼠标" +
          +
          +
          +
          + +
          + +
          + +
          +
          +
          品牌:
          +
          +
            +
          • 所有品牌
          • +
          • A
          • +
          • B
          • +
          • C
          • +
          • D
          • +
          • E
          • +
          • F
          • +
          • G
          • +
          • H
          • +
          • I
          • +
          • J
          • +
          • K
          • +
          • L
          • +
          • M
          • +
          • N
          • +
          • O
          • +
          • P
          • +
          • Q
          • +
          • R
          • +
          • S
          • +
          • T
          • +
          • U
          • +
          • W
          • +
          • X
          • +
          • Y
          • +
          • Z
          • +
          +
          +
          + +
          +
          已选条件:
            +
            + 确定 + 取消 +
            +
            +
            + 更多 + 多选 +
            +
            +
            +
            +
            +
            外设产品:
            +
            +
            + +
            +
            + 确定 + 取消 +
            +
            +
            + 更多 + +
            +
            +
            + +
            +
            +
            电脑整机:
            +
            +
            + +
            +
            + 确定 + 取消 +
            +
            +
            + 更多 + +
            +
            +
            + +
            +
            +
            连接方式:
            +
            +
            + +
            +
            + 确定 + 取消 +
            +
            +
            + + 多选 +
            +
            +
            +
            +
            +
            适用场景:
            +
            +
            + +
            +
            + 确定 + 取消 +
            +
            +
            + + +
            +
            +
            +
            +
            +
            高级选项:
            + +
            + + + + + + + + + + + +
            +
            +
            +
            +
            +
            + + + + +
            + + + +
            + +
            <上一页1234567...下一页>100页  到第确定
            +
            +
            +
            +
            +
            + +

            商品精选

            +
            +
              +
            +
            +
            + + +
            +
            + +
            + + +
            +
            +
            +
            +
            + +
            商品精选
            +
            +
            +
            +
            + +
            +
            +

            猜你喜欢

            加载中,请稍候...
            +
            + +
            +
            +
              +
            1. + 品类齐全,轻松购物 +
            2. +
            3. + 多仓直发,极速配送 +
            4. +
            5. + 正品行货,精致服务 +
            6. +
            7. + 天天低价,畅选无忧 +
            8. +
            +
            +
            +
            +
            +
            +
            购物指南
            +
            + 购物流程 +
            +
            + 会员介绍 +
            +
            + 生活旅行/团购 +
            +
            + 常见问题 +
            +
            + 大家电 +
            +
            + 联系客服 +
            +
            +
            +
            配送方式
            +
            + 上门自提 +
            +
            + 211限时达 +
            +
            + 配送服务查询 +
            +
            + 配送费收取标准 +
            +
            + 海外配送 +
            +
            +
            +
            支付方式
            +
            + 货到付款 +
            +
            + 在线支付 +
            +
            + 分期付款 +
            +
            + 公司转账 +
            +
            +
            +
            售后服务
            +
            + 售后政策 +
            +
            + 价格保护 +
            +
            + 退款说明 +
            +
            + 返修/退换货 +
            +
            + 取消订单 +
            +
            +
            +
            特色服务
            +
            + 夺宝岛 +
            +
            + DIY装机 +
            +
            + 延保服务 +
            +
            + 京东E卡 +
            +
            + 京东通信 +
            +
            + 京鱼座智能 +
            +
            + +
            +
            +
            +
            + + +

            京东会员

            京东会员 0
            成功加入购物车!
            购物车
            成功加入购物车!
            我的消息 0
            成功加入购物车!
            + + + + + + \ No newline at end of file