python 网页抓取(使用代理服务器),解析一例
来源:百度文库 编辑:神马文学网 时间:2024/04/28 20:12:33
Java代码
- #coding:utf-8
- '''
- Created on 2009-7-15
- @author: Administrator
- '''
- import urllib2
- import newhttplib
- import lxml.html as x
- def getmusic(num,soc=None):
- s=num.split(':')
- s[0]=s[0].strip()
- s[1]=s[1].strip()
- s[2]=s[2].strip()
- h1 = newhttplib.HTTPConnection('10.0.0.172',80)
- h1.auto_open = 0
- h1.connect(soc)
- url='http://218.200.160.29/s3/i/app/search/musicResult.jsp?qd=1956&CH=12530-wap-lslb&v=1864&tplpath=/s3/i/qrc/&type=all&keyword='+urllib2.quote(s[0]+" "+s[1])
- h1.request("GET",url)
- r1 = h1.getresponse()
- content=r1.read()
- doc=x.document_fromstring(content)
- alist=doc.xpath("//a")
- print s[0],s[1]
- for a in alist:
- c1= a.text_content()
- try:
- if c1.find(s[0])>=0 and c1.find(s[1])>=0:
- print c1
- print c1.find(s[0]),c1.find(s[1])
- nexturl='http://218.200.160.29'+a.get('href')
- h1.request("GET",nexturl)
- r1 = h1.getresponse()
- content=r1.read()
- print content
- doc=x.document_fromstring(content)
- blist=doc.xpath("//a")
- for b in blist:
- bcontent=b.text_content()
- if bcontent.find('高潮版')>=0 or bcontent.find('超长版')>=0:
- print bcontent
- bhref= b.get('href')
- nnexturl='http://218.200.160.29'+bhref
- h1.request("GET",nnexturl)
- r1 = h1.getresponse()
- ccontent=r1.read()
- #print ccontent
- doc=x.document_fromstring(ccontent)
- clist=doc.xpath("//a")
- for c in clist:
- chref=c.get('href')
- if chref.find('218.200.160.10')>=0:
- print chref
- sb2=s[2][11:]
- print sb2
- if chref.find(sb2)>=0:
- print u'找到匹配歌曲开始下载。。。'
- h1.request("GET",chref)
- r1 = h1.getresponse()
- print r1.status
- dcontent=r1.read()
- f=open('./test.mp3','wb')
- f.write(dcontent)
- f.close()
- except BaseException,e:
- print e
- if __name__ == '__main__':
- getmusic('相信:曾建军:600902000005714466')
python 网页抓取(使用代理服务器),解析一例
python 网页抓取经验
代理服务器(Proxy)完全解析
通过代理服务器 使用 XMLHTTP
代理服务器使用教程指南
抽取示例 -- 网页数据抓取,网页文本抓取,信息采集
浏览网页更方便 IE7使用技巧30招(一)
免费代理服务器地址和使用设置
免费代理服务器地址和使用设置
代理猎手及代理服务器使用详解
使用Go语言实现的代理服务器
免费代理服务器地址和使用设置
代理服务器使用原理与选购细则
网页画面抓取软件:URL2BMP和HprSnap5等
搜索引擎喜欢抓取什么格式的网页内容?
NUTCH介绍--抓取(1)
网页编程入门(一)
网页禁止使用“复制”、“粘贴(转载)
博客园 - Java, Python, Jython and .NET. - Subversion配置安装教程(一)
代理服务器使用教程指南(解决教育网不能访问国外网站)
使用HTTP代理服务器的安全性简评-月光博客
怎样使用免费代理服务器隐藏上网IP地址
怎样使用免费代理服务器隐藏上网IP地址
如何使用代理服务器上网,从基础到高手