python如何爬取百度云连接方法指导


本文摘自php中文网,作者巴扎黑,侵删。

本篇文章主要介绍了python urllib爬取百度云连接的实例代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

翻看自己以前写的程序,发现写过一个爬取盘多多百度云资源的东西,完全是当时想看变形金刚才自己写的,而且当时第一次接触python大概写了有2天才搞出来这个程序,学习python语言,可以看得出来那时候的代码写的真的low。虽然现在也不怎么样,哈哈,一直学习中,不做过多解释,上图上代码,因为变量的声明是什么我自己也忘了(手动傲娇),连写入文件当时都不会哈哈哈哈哈哈哈哈,也不知道class中可以通过init初始化,唉学习python原来我学到了这么多东西,感谢python


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

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://www.panduoduo.net/s/name/'+search_text)

 

 

'''获取百度云地址'''

def getbaidu(adr):

  for i in adr:

    url = urllib.urlopen('http://www.panduoduo.net'+i)

    bs = BeautifulSoup(url)

    bs1 = bs.select('.dbutton2')

    href = re.compile('http\%(\%|\d|\w|\/\/|\/|\.)*')

    b = href.search(str(bs1))

    name = str(bs.select('.center')).decode('utf-8')

    text1 = re.compile('\<h1\sclass\=\"center"\>[\d|\w|\D|\W]*\</h1\>')

    text2 = text1.search(name)

    rag1 = re.compile('\>[\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.compile('\/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如何爬取百度云连接方法指导的详细内容,更多文章请关注木庄网络博客!!

相关阅读 >>

Python基础学习总结(四)

Python中二叉堆的详细介绍(代码示例)

Python最长回文串算法

Python正式对外发布的年份

Python需要什么软件

零基础学Python怎么打开图片

Python中is 和 ==的详细解析(附代码)

Python属于开源语言吗

Python怎么读csv文件

Python操作sqlite数据库与文件操作的实例详解

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...