python google play
#!/usr/env python
#-*- coding: utf-8 -*-
import urllib
import urllib2
import random
import requests
import os,sys
import MySQLdb
from sgmllib import SGMLParser
from BeautifulSoup import BeautifulSoup
import re
num=0
def main():
try:
conn=MySQLdb.connect(host='localhost',user='root',passwd='123456',db='googlemarket',charset="utf8")
conn.query("set names utf8")
except Exception,e:
print e
sys.exit()
cursor=conn.cursor()
category=['PERSONALIZATION','TRANSPORTATION','SPORTS','HEALTH_AND_FITNESS','APP_WALLPAPER','COMICS','MEDICAL','BUSINESS','BOOKS_AND_REFERENCE','WEATHER','ENTERTAINMENT','MEDIA_AND_VIDEO','APP_WIDGETS','TOOLS','PHOTOGRAPHY','PRODUCTIVITY','EDUCATION','NEWS_AND_MAGAZINES','TRAVEL_AND_LOCAL','LIFESTYLE','SOCIAL','FINANCE','SHOPPING','LIBRARIES_AND_DEMO','COMMUNICATION','MUSIC_AND_AUDIO','GAME']
for k in range(0,27):
t="https://play.google.com/store/apps/category/"+category[k]
html=requests.get(t)
preresult=html.content
soup=BeautifulSoup(preresult)
result=soup.prettify("utf-8")
pattern=re.compile('<a class="title" href="(.+?)" title')
dataresult=re.findall(pattern,result)
dataresult=list(set(dataresult))
for i in dataresult:
url="https://play.google.com"+i
print url
#url="https://play.google.com/store/apps/details?id=com.androidesk&hl=zh_CNhttps%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcom.androidesk" html=requests.get(url)
preresult=html.content
soup=BeautifulSoup(preresult)
result=soup.prettify("utf-8")
#名称
pattern=re.compile('<div class="document-title" itemprop="name">[\s\S]*?<div>([\s\S]*?)</div>')
data0=re.findall(pattern,result)
for items in data0:
print items
#制造商
pattern=re.compile('itemprop="name">([\s\S]*?)</a>')
data1=re.findall(pattern,result) make=data1[0].split("\n") print make[8]
#版本
pattern=re.compile('itemprop="softwareVersion">([\s\S]*?)</div>')
data2=re.findall(pattern,result)
print data2[0]
#更新时间
pattern=re.compile('itemprop="datePublished">([\s\S]*?)</div>')
data3=re.findall(pattern,result)
print data3[0]
#文件大小
pattern=re.compile('itemprop="fileSize">([\s\S]*?)</div>')
data4=re.findall(pattern,result)
print data4[0]
#支持固件
pattern=re.compile('itemprop="operatingSystems">([\s\S]*?)</div>')
data5=re.findall(pattern,result)
print data5[0]
#说明
pattern=re.compile('itemprop="description">[\s\S]*?<div>([\s\S]*?)</div>')
data6=re.findall(pattern,result)
for items in data6:
print re.sub('[<br /> <p> </p>]',' ',items)
sql="insert into address(name,version,developer,pubtime,filesize,support,introduction) values(%s,%s,%s,%s,%s,%s,%s)"
for items in data6: if(data5):
#values=(data0[0],data1[0],data2[0],data3[0],data4[0],data5[0],re.sub('<br />',' ',items))
#else:
#values=(data0[0],data1[0],data2[0],data3[0],data4[0],'NULL',re.sub('<br />',' ',items))
#print values
#print sql % values
#cursor.execute(sql,values)
#conn.commit()
pattern=re.compile('<img class="cover-image" src=(.+?) alt="Cover art" itemprop="image" />')
data=re.findall(pattern,result)
global num
for j in data:
print j
print type(j)
headers = {'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201'}
temp=requests.get(j[1:-2], headers=headers)
f=file("googlemarket/"+str(num),"w+")
num=num+1
print num
f.write(temp.content) if __name__=="__main__":
main()
<type 'str'>
Traceback (most recent call last):
File "crawler0729.py", line 103, in <module>
main()
File "crawler0729.py", line 91, in main
temp=requests.get(j[1:-2], headers=headers)
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 55, in get
return request('get', url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 335, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 438, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 327, in send
raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='lh3.ggpht.com', port=443): Max retries exceeded with url: /RBld17rLw4Ik0JtOaKk4bZB2RiGJ2R8H5Q8Rjw3Hh6BAM694fOzzKj1TJFr7R02ZS_40=w30 (Caused by <class 'socket.error'>: [Errno 101] Network is unreachable)
python google play的更多相关文章
- Python+Google Geocoding
本文主要介绍使用Python调用Google Geocoding API进行地址到地理坐标的转换. Google Geocoding参考https://developers.google.com/ma ...
- 吴裕雄--天生自然python Google深度学习框架:Tensorflow实现迁移学习
import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...
- 详解Python Google Protocol Buffer
为什么要使用PB? PB(Protocol Buffer)是 Google 开发的用于结构化数据交换格式,作为腾讯云日志服务标准写入格式.因此用于写入日志数据前,需要将日志原始数据序列化为 PB 数据 ...
- 吴裕雄--天生自然python Google深度学习框架:经典卷积神经网络模型
import tensorflow as tf INPUT_NODE = 784 OUTPUT_NODE = 10 IMAGE_SIZE = 28 NUM_CHANNELS = 1 NUM_LABEL ...
- 吴裕雄--天生自然python Google深度学习框架:图像识别与卷积神经网络
- 吴裕雄--天生自然python Google深度学习框架:MNIST数字识别问题
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_NODE = 784 ...
- 吴裕雄--天生自然python Google深度学习框架:深度学习与深层神经网络
- 吴裕雄--天生自然python Google深度学习框架:TensorFlow实现神经网络
http://playground.tensorflow.org/
- 吴裕雄--天生自然python Google深度学习框架:Tensorflow基础应用
import tensorflow as tf a = tf.constant([1.0, 2.0], name="a") b = tf.constant([2.0, 3.0], ...
随机推荐
- Java学习----Math函数
public class TestMath { public static void main(String[] args) { System.out.println(Math.E); System. ...
- 常用原生JS兼容性写法汇总
1.添加事件方法 addHandler:function(element,type,handler){ if(element.addEventListener){//检测是否为DOM2级方法 elem ...
- OpenCV for c++Builder
整理日: 20154/6 Borland C++BuilderでOpenCVを使う 確認 Turbo C++ 2007/03 1. ダウンロード&インストール http://sourcefor ...
- Android计量单位px,in,mm,pt,dp,dip,sp和获取屏幕尺寸与密度
###########################################Android计量单位########################################### px ...
- open files
/* * * Copyright (c) International Business Machines Corp., 2001 * * This program is free software; ...
- BZOJ 2242 计算器
Description 你被要求设计一个计算器完成以下三项任务: \(1.\)给定\(y,z,p\),计算\(y^{z}\;mod\;P\)的值: \(2.\)给定\(y,z,p\),计算满足\(xy ...
- spoj 3885
简单的博弈题,用dp解: 每个人只能拿1,l,k个硬币: dp[i][j]表示第j个人拿是否能拿第i枚硬币: 代码: #include<cstdio> #define maxn 10000 ...
- call和apply还有bind
有图有真相 function myfun1(){ //这是私有属性 var private1 = "这是私有属性1"; var privateMethod = function() ...
- andorid studio
http://www.cnblogs.com/smyhvae/p/4390905.html
- 《深度探索c++对象模型》chapter3 Data语意学
一个空的class:如 class X{} ; sizeof(X)==1; sizeof为什么为1,他有一个隐晦的1 byte,那是被编译器安插进去的一个char,这使得class2的两个object ...