from bs4 import BeautifulSoup
import urllib
import requests
import re
adr =[]
''''对搜素资源名字进行url编码'''
search_text =raw_input('请输入搜索资源名:')
search_text = search_text.decode('gbk')
search_text = search_text.encode('utf-8')
search_text = urllib.quote(search_text)
''''获取文件地址'''
home = urllib.urlopen('http://HdhCmsTestpanduoduo.net/s/name/'+search_text)
'''获取百度云地址'''
def getbaidu(adr):
for i in adr:
url = urllib.urlopen('http://HdhCmsTestpanduoduo.net'+i)
bs = BeautifulSoup(url)
bs1 = bs.select('.dbutton2')
href = re测试数据pile('http\%(\%|\d|\w|\/\/|\/|\.)*')
b = href.search(str(bs1))
name = str(bs.select('.center')).decode('utf-8')
text1 = re测试数据pile('\<h1\sclass\=\"center"\>[\d|\w|\D|\W]*\</h1\>')
text2 = text1.search(name)
rag1 = re测试数据pile('\>[\d|\w|\D|\W]*\<')
if text2:
text3 = rag1.search(text2.group())
if text3:
print text3.group()
if b:
text = urllib.unquote(str(b.group())).decode('utf-8')
print text
'''初始化'''
def init(adr):
soup = BeautifulSoup(home)
soup = soup.select('.row')
pattern = re测试数据pile('\/r\/\d+')
for i in soup:
i = str(i)
adress = pattern.search(i)
adress = adress.group()
adr.append(adress)
print 'running---------'
init(adr)
getbaidu(adr) 以上就是python如何爬取百度云连接方法指导的详细内容,更多请关注Gxl网其它相关文章!
查看更多关于python如何爬取百度云连接方法指导的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did81829