beautifulsoup 简单使用

直接上码,抓的是安智市场的数据

#-*-coding:utf-8-*-
from bs4 import BeautifulSoup
import urllib
import re
import xlwt
i = 1

data = xlwt.Workbook()
sheet = data.add_sheet(“sheet 1″)
row = 0
while i < 8:
path = ‘http://www.anzhi.com/list_1_’ + str(i) + ‘_hot.html’
html = urllib.urlopen(path)
url = “http://www.anzhi.com”
text = html.read()
soup = BeautifulSoup(text)
temps = soup.find_all(‘span’, attrs={“class”: “app_name”})
for temp in temps:
url_temp = url + temp.find(‘a’)['href']
if temp.find(‘a’)['href'] == ‘/soft_996309.html’:
continue
html = urllib.urlopen(url_temp)
text_app = BeautifulSoup(html)
app_temp = text_app.find(‘div’, {“class”:”detail_description”})
#游戏名称
app_name = app_temp.find(‘h3′)
app_name = app_name.text
sheet.write(row,0,app_name)
#下载次数

down_num = text_app.find(‘ul’,{“id”:”detail_line_ul”})
down_num = down_num.find(‘span’,attrs={“class”:”spaceleft”})
down_num = down_num.text
sheet.write(row,1,down_num)

developer_temp = text_app.find(‘div’,{“class”:”detail_description”})
dev_temps = developer_temp.find_all(‘div’,{“class”:”detail_line”})
dev_temp = dev_temps[2]
dev = dev_temp.find(‘span’)
temp = dev.text
sheet.write(row,2,temp)

#应用介绍
app_temp = text_app.find(‘div’,{“class”:”app_detail_list”})
app_info = app_temp.p.text
sheet.write(row,3,app_info)
#包名
app_wkey = text_app.find(‘div’,{“class”:”detail_icon”})
app_wkeys = app_wkey.find_all(‘a’)
for app_wkey in app_wkeys:
m = re.search(‘package=’,str(app_wkey))
if m is not None:
wkeys = re.split(‘package=’, str(app_wkey))
key = re.split(‘”>’,wkeys[1])[0]
sheet.write(row,4,key)
#下载地址
download = text_app.find(‘div’,{“class”:”detail_icon”})
down_temp = download.find(‘li’,{“id”:”install_wdj”})
down_temp = down_temp.find(‘a’)['href']
download_str = url + down_temp + “&n=5″
sheet.write(row,5, download_str)
row = row + 1
i = i + 1

data.save(‘test.xls’)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值