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], ...
随机推荐
- Linux环境下添加ftp账号步骤
(1)远程登录Linux服务器所用的工具,免费开源,可以从网站上很容易就下载到. (2)打开putty,输入服务器IP,进入后按提示进入用户名和密码输入超级管理员 root,然后系统让输入密码,注意此 ...
- struts2 package元素
<package../>元素 name 必选 包名 extends 可选 继承 namespace ...
- Linux平台上搭建apache+tomcat负载均衡集群
传统的Java Web项目是通过tomcat来运行和发布的.但在实际的企业应用环境中,采用单一的tomcat来维持项目的运行是不现实的.tomcat 处理能力低,效率低,承受并发小(1000左右).当 ...
- ubuntu 14.04安装quickbuild buildagent (二)
使用方法: /home/carloz/programfiles/quickbuild6/buildagent/bin/agent.sh start /home/carloz/programfiles/ ...
- linux下date命令实现时间戳与日期的转换
1.查看指定时间的时间戳 查看当前时间 #date +%s 查看指定时间 #date -d 2008-01-01 +%s 1199116800 #date -d 20080101 ...
- 简单学C——第四天
数组 在学数组之前,有必要把前面的知识复习一遍,当然我的复习,仅仅只是提一下,而对于你,则应该认真的看一下前面的知识点,不懂可以百度,哈哈. 前面我们大致学了 1.定义变量,2.数据的输入与输出,3. ...
- django中文件(头像)上传
一些常用的小功能,记录下来 先说一种上传功能. 模板表单 <form enctype="multipart/form-data" name="form1" ...
- maven web项目不能创建src/main/java等文件夹的问题
eclipse创建maevn web项目,在选择maven_archetype_webapp原型后,默认只有src/main/resources这个Source Floder. 按照maven目录结 ...
- Java 高效检查一个数组中是否包含某个值
如何检查一个数组(未排序)中是否包含某个特定的值?在Java中,这是一个非常有用并又很常用的操作.同时,在StackOverflow中,有时一个得票非常高的问题.在得票比较高的几个回答中,时间复杂度差 ...
- The Greate Wall 相关网络知识(一)域名劫持
什么叫做DNS? DNS(Domain Name System,域名系统),因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去记住能够被机器直接读取的IP数串 ...