beautifulsoup 简单使用
来源:互联网 发布:microservices java 编辑:程序博客网 时间:2024/05/29 09:09
直接上码,抓的是安智市场的数据
#-*-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’)
- beautifulsoup 简单使用
- BeautifulSoup模块的简单使用
- python中BeautifulSoup简单使用
- 使用BeautifulSoup实现简单豆瓣爬虫
- 使用BeautifulSoup的简单小爬虫
- 使用beautifulsoup
- BeautifulSoup使用
- BeautifulSoup使用
- BeautifulSoup使用
- 简单爬虫python实现02——BeautifulSoup的使用
- BeautifulSoup的简单使用和抓取静态页面图片
- 使用python语言结合beautifulsoup编写简单的网络爬虫
- beautifulsoup的简单用法
- Python BeautifulSoup 简单笔记
- beautifulsoup的简单用法
- Python BeautifulSoup 简单笔记
- Python BeautifulSoup 简单笔记
- python beautifulsoup简单用法
- 2014最值得学习的语言—必须是R
- 利用pinyin4j将汉字转换为拼音完整示例
- Android面试汇总
- ajax基础代码
- 关于Qt for Android的移植需要注意的事项
- beautifulsoup 简单使用
- 关于静态常量的编译
- HTTP报文
- 《SLIC Superpixels》阅读笔记
- 如何实现工作流控件BizFlow 的分支
- android 录音机笔记
- 第三次作业
- sleep和wait有什么区别
- UML之活动图