码迷,mamicode.com
首页 > 编程语言 > 详细

python爬取京东菜单

时间:2016-09-01 17:59:51      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:

#!/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()

python爬取京东菜单

标签:

原文地址:http://www.cnblogs.com/itgg168/p/5830478.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!