文章摘要: 首先要使用開發者工具找到全部商品分類所在的層級,接下來寫程式碼來讀取該層級下的文字和超鏈接。先看原始碼;圖上還顯示了使用了京東自己的框架Nerv框架,相關內容及生態你可以通過官網瞭解更多。
python讀取京東首頁的全部商品分類,首先要使用開發者工具找到全部商品分類所在的層級,
接下來寫程式碼來讀取該層級下的文字和超鏈接。

圖上還顯示了使用了京東自己的框架Nerv框架,相關內容及生態你可以通過官網瞭解更多。
https://nerv.aotu.io/


顯示了所有商品分類。
from __future__ import print_function
import requests
import sys
#reload(sys)
#sys.setdefaultencoding(“utf-8”)
import importlib
importlib.reload(sys)
from lxml import etree;
#列印京東商品分類
resp =requests.get(‘https://www.jd.com’)
doc_main=etree.HTML(resp.content.decode(“utf-8”))
for x in doc_main.xpath(“//body/div/div/div/div/div/ul/li”):
print(*x.xpath(“a/text()”)+x.xpath(“a/@href”))