Traceback (most recent call last):
File "androidmarket82.py", line 108, in main()
File "androidmarket82.py", line 54, in main
pattern=re.compile(')
')#版本号
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('''.+?''')
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('')#名称
data0=re.findall(pattern,result)
print data0[0]
pattern=re.compile(')
')#类别
data6=re.findall(pattern,result)
print data6[0]
pattern=re.compile('')#介绍
data7=re.findall(pattern,result)
for items in data7:
pass#print re.sub(' ',' ',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(' ',' ',items))
except:
pass
try:
cursor.execute(sql,values)
conn.commit()
except:
pass
pattern=re.compile('
[\s\S]*?')
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()
网上关于SQL优化的教程很多,但是比较杂乱。近日有空整理了一下,写出来跟大家分享一下,其中有错误和不足的地方,还请大家纠正补充。
这篇文章我花费了大量的时间查找资料、修改、排版,希望大家阅读之后,感觉好的话推荐给更多的人,让更多的人看到、纠正以及补充。
1.对查询进行优化,要尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引。
2.应尽量避免在 where
Zookeeper类是Zookeeper提供给用户访问Zookeeper service的主要API,它包含了如下几个内部类
首先分析它的内部类,从WatchRegistration开始,为指定的znode path注册一个Watcher,
/**
* Register a watcher for a particular p
何为部分应用函数?
Partially applied function: A function that’s used in an expression and that misses some of its arguments.For instance, if function f has type Int => Int => Int, then f and f(1) are p