Skip to content
lnf0701 edited this page Jul 12, 2015 · 2 revisions

pip install Requests http://www.lfd.uci.edu/~gohlke/pythonlibs/

安装和配置pycharm 正则表达式符号与方法: findall,search,sub 技巧: .,匹配任意字符除了换行符号"\n" ,匹配前一个字符0次或无数次 ?,匹配前一个字符0次或1次。 b=re.findall('pattern',string) 需要掌握的一个(.?):尽可能少的匹配。少量多餐。 -------------.?------------注意和上面带括号的匹配。 re.findall('xx(.?)xx',string,re.S):re.S忽略换行符

search 和 findall区别: re.search('xx(.?)xx123xx(.?)xx',string).group(2) re.findall('xx(.?)xx123xx(.?)xx',string) f2[0][1] -------find返回的是列表。

匹配纯数字方法(\d+)

应用举例: re.search:如果确定找的内容在页面中只有一行,就用这个,

先抓大,在抓小, we = re.findall('

    (.*?)
',html,re.S)[0] wes = re.findall('pattern',we,re.S)

实战: tupian = re.findall('img src="(.*?)" class="lessoning",html,re.S') i=0 for each in tupian: print 'now downloading:' + each pic = requests.get(each) fp = open('pic\'+str(i)+'.jpg',wb) fp.write(pic.content) fp.close() i +=1 sleep 2

Clone this wiki locally