Traceback (most recent call last):
  File "androidmarket82.py", line 108, in <module>

    main()

  File "androidmarket82.py", line 54, in main

    pattern=re.compile('<label id="ctl00_AndroidMaster_Content_Apk_SoftVersionName">(.+?)</label>)</div>')#版本号

  File "/usr/lib/python2.7/re.py", line 190, in compile

    return _compile(pattern, flags)

  File "/usr/lib/python2.7/re.py", line 242, in _compile

    raise error, v # invalid expression

sre_constants.error: unbalanced parenthesis

#!/usr/env  python
#-*- coding: utf-8 -*-
import requests
import os,sys
import time
import MySQLdb
import re
num=0
dataresult=[]
def main():
try:
conn=MySQLdb.connect(host='localhost',user='root',passwd='123456',db='addressbookdb',charset="utf8")
conn.query("set names utf8")
except Exception,e:
print e
sys.exit()
cursor=conn.cursor()
for k in range(51):
try: url="http://apk.hiapk.com/apps#"+str(k)+"_1_0_0_0_0_0"
print url
html=requests.get(url)
result=html.content
pattern=re.compile('''<a target='_blank' title=".+?" href="(.+?)">.+?</a></span>''')
daresult=re.findall(pattern,result)
global dataresult
dataresult+=daresult
dataresult=list(set(dataresult))
print len(dataresult)
except: time.sleep(30)
pass f=file("androidmarket.txt","a+")
content=str(len(dataresult))
f.write(content)
f.close()
print len(dataresult)
for i in dataresult: print i
try:
html=requests.get(i)
result=html.content
except:
time.sleep(30)
pass
pattern=re.compile('<label id="ctl00_AndroidMaster_Content_Apk_SoftName">(.+?)</label>')#名称
data0=re.findall(pattern,result)
print data0[0]
pattern=re.compile('<label id="ctl00_AndroidMaster_Content_Apk_SoftVersionName">(.+?)</label>)</div>')#版本号
data1=re.findall(pattern,result)
print data1[0]
pattern=re.compile('<span class="d_u_line"><label id="ctl00_AndroidMaster_Content_Apk_SoftDeveloper">(.+?)</label>')#开发者
data2=re.findall(pattern,result)
print data2[0]
pattern=re.compile('<label id="ctl00_AndroidMaster_Content_Apk_SoftPublishTime">(.+?)</label>')#发布时间
data3=re.findall(pattern,result)
print data3[0]
pattern=re.compile('<span class="font14"><label id="ctl00_AndroidMaster_Content_Apk_SoftSize">(.+?)</label>')#文件大小
data4=re.findall(pattern,result)
print data4[0]
pattern=re.compile('<span class="font14 d_gj_line"><label id="ctl00_AndroidMaster_Content_Apk_SoftSuitSdk">(.+?)</label>')#支持固件
data5=re.findall(pattern,result)
print data5[0]
pattern=re.compile('<span id="ctl00_AndroidMaster_Content_Apk_SoftCategory" class="font14">(.+?)</span></a></span></div>')#类别
data6=re.findall(pattern,result)
print data6[0]
pattern=re.compile('<label id="ctl00_AndroidMaster_Content_Apk_Description">([\s\S]*?)</label>')#介绍
data7=re.findall(pattern,result)
for items in data7:
pass#print re.sub('<br />',' ',items)
sql="insert into androidmarket(name,version,developer,pubtime,filesize,support,classifyintroduction) values(%s,%s,%s,%s,%s,%s,%s,%s)"
for items in data7:
try: values=(data0[0],data1[0],data2[0],data3[0],data4[0],data5[0],data6[0],re.sub('<br />',' ',items)) except:
pass
try:
cursor.execute(sql,values)
conn.commit()
except:
pass
pattern=re.compile(' <div class="appTitle clearfix">[\s\S]*?<img src=(.+?)/>')
data=re.findall(pattern,result)
for j in data:
print j try:
temp=requests.get(j[1:-2])
except:
time.sleep(30)
pass
global num
f=file("androidmarket/"+str(num),"w+")
num=num+1
print num
f.write(temp.content)
cursor.close()
conn.close()
f.close()
if __name__=="__main__":
main()

sre_constants.error: unbalanced parenthesis的更多相关文章

  1. System Error Codes

    很明显,以下的文字来自微软MSDN 链接http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx M ...

  2. winerror.h中的内容(可以查看last error对应)

    /************************************************************************* ** winerror.h -- error co ...

  3. Windows Error Codes

    http://www.briandunning.com/error-codes/?source=Windows Windows Error Codes List All Error Codes | S ...

  4. Shell script fails: Syntax error: “(” unexpected

    Shell script fails: Syntax error: “(” unexpected google 一下. http://unix.stackexchange.com/questions/ ...

  5. matlab画图(一)

    例1.画出函数图像 >> x=-pi/2:0.01:pi/2; >> y=x+sin(x)+exp(x); >> plot(x,y,'r','Linewidth', ...

  6. 让ecshop模板支持php运算

    让ecshop模板支持php运算在 cls_template.php 底部加入函数: /** * 处理if标签 * * @access public * @param string $tag_args ...

  7. 【JAVA】通过公式字符串表达式计算值,网上的一种方法

    public class Test {    public static void main(String[] args) {     SimpleCalculator s=new SimpleCal ...

  8. angularJs的ui-router总结

    一:跑通ui-router. ui-router源码在最后面 跑通后的样子: 这个不解释了,都是很基本的东西. 二:切换视图: 这里的name可以不写,但是你得放到state的第一个参数里. 跑起来后 ...

  9. python的正则表达式 re

    python的正则表达式 re 本模块提供了和Perl里的正则表达式类似的功能,不关是正则表达式本身还是被搜索的字符串,都可以是Unicode字符,这点不用担心,python会处理地和Ascii字符一 ...

随机推荐

  1. Java [Leetcode 172]Factorial Trailing Zeroes

    题目描述: Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be ...

  2. ActionBarSherlock的学习笔记(四) ------------ ActionBarSherlock中的搜索及SearchView的使用

    在使用ActionBarSherlock定义app的头部操作时,会经常看见搜索的动作,本文主要介绍一下搜索是如何实现的. 1. SearchView 是搜索的核心组件,具体介绍请参考Android官方 ...

  3. SSH整合所需jar

    Struts2.1.8+Hibernate3.2+Spring4.1.6+MySql ant-1.6.5.jar ant-antlr-1.6.5.jar ant-junit-1.6.5.jar ant ...

  4. 【大数加法】POJ-1503、NYOJ-103

    1503:Integer Inquiry 总时间限制:  1000ms 内存限制:  65536kB 描述 One of the first users of BIT's new supercompu ...

  5. angular+rails集成实战

    http://start.jcolemorrison.com/setting-up-an-angularjs-and-rails-4-1-project/ 1. 添加gemgem 'sprockets ...

  6. mysql open files

    错误信息如下: ..... 150905 13:10:17 [ERROR] /usr/local/mysql/bin/mysqld: Can't open file: './mytest/t1.frm ...

  7. (原创)LAMP教程2-安装虚拟机软件VirtualBox

    大家好,今天我们讲的是第二章,安装虚拟机软件VirtualBox 我先讲一下我的电脑的环境,可以看下面的图片说明 大家也看到了我的机子是64位的win7系统(为什么讲这个,因为接下来我们要下载的是ce ...

  8. C# 中如何判断某个字符串是否为空的方法 分享了三个方法来判断字

    1. 三种常用的字符串判空串方法:Length法:bool isEmpty = (str.Length == 0);Empty法:bool isEmpty = (str == String.Empty ...

  9. C++实现离散余弦变换(参数为Eigen矩阵)

    C++实现离散余弦变换(参数为Eigen矩阵) 问题描述 昨天写了一个参数为二维指针为参数的离散余弦变换,虽然改进了参数为二维数组时,当数组大小不确定时声明函数时带来的困难,但使用指针作为参数也存在一 ...

  10. hadoop1.2.1 伪分布式配置

    主要配置 core-site.xml hdfs-site.xml mapred-site.xml