好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Python爬取京东商品分类与链接

前言

本文主要的知识点是使用Python的 BeautifulSoup 进行多层的遍历。

如图所示。只是一个简单的哈,不是爬取里面的隐藏的东西。

示例代码

from bs4 import BeautifulSoup as bs
import requests
headers = {
  "host": "HdhCmsTestjd测试数据",
  "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36 Core/1.47.933.400 QQBrowser/9.4.8699.400",
  "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
  }
session = requests.session()
def get_url():
  renspned = bs(session.get('http://HdhCmsTestjd测试数据/',headers = headers).text,'html.parser')
  for i in renspned.find("p", {"class": "dd-inner"}).find_all("a",{"target":"_blank"}):
    print(i.get_text(),':',i.get('href'))
get_url() 

更多Python爬取京东的商品分类与链接相关文章请关注PHP中文网!

查看更多关于Python爬取京东商品分类与链接的详细内容...

  阅读:37次