python爬取京东菜单

#!/usr/bin/python
#encoding=utf-8
from bs4 import BeautifulSoup as bs
import requests
headers = {
"host": "www.jd.com",
"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://www.jd.com/',headers = headers).text,'html.parser')
  for i in renspned.find("div", {"class": "dd-inner"}).find_all("a",{"target":"_blank"}):
    print(i.get_text(),':',i.get('href'))
get_url()

posted @ 2016-09-01 16:44  蜗牛123  阅读(317)  评论(0编辑  收藏  举报