Python学习资源分享,包括:
1. Python环境安装
2. Python错误排查
3. Python常用函数查询与解释目录
3.1.7解决“ python unicode is not defined”错误
提示…
37
3.1.8解决“ Attribute error:'dict' object has no
attribute has key”错误提示
38
3.1.9解决“ ImportError: No module named urllib2”
错误提示
38
3.2常见错误
本文实例讲述了Python抓取淘宝下拉框关键词的方法。分享给大家供大家参考。具体如下:
import urllib2,re
for key in open('key.txt'):
do = "http://suggest.taobao.com/sug?code=utf-8&q=%s" % key.rstrip()
_re = re.findall('\[\"(.*?)\",\".*?\"\]',urllib2.urlopen(do).read())
for i in _re : p
如下所示:
f = open('./val.txt')
lines = f.readlines() #整行读取
f.close()
for line in lines:
rs = line.rstrip('\n') #去除原来每行后面的换行符,但有可能是\r或\r\n
newname=rs.replace(rs,'/JPEGImages/'+rs+'.jpg'+' '+'/SegmentationClassAug/'+rs+'.png')
newfile=open('.val1.txt'