python urllib爬取百度云连接的实例代码

yipeiwu_com5年前Python爬虫

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

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 requests抓取one推送文字和图片代码实例

这篇文章主要介绍了python requests抓取one推送文字和图片代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 req...

python3实现抓取网页资源的 N 种方法

这两天学习了python3实现抓取网页资源的方法,发现了很多种方法,所以,今天添加一点小笔记。 1、最简单 import urllib.request response = url...

Docker部署Python爬虫项目的方法步骤

1) 首先安装docker: # 用 yum 安装并启动 yum install docker -y && systemctl start docker 2) 下载自定义镜像需要...

Python爬虫实现百度图片自动下载

Python爬虫实现百度图片自动下载

制作爬虫的步骤 制作一个爬虫一般分以下几个步骤: 分析需求分析网页源代码,配合开发者工具编写正则表达式或者XPath表达式正式编写 python 爬虫代码 效果预览 运行效果如下:...

python3写爬取B站视频弹幕功能

python3写爬取B站视频弹幕功能

需要准备的环境: 一个B站账号,需要先登录,否则不能查看历史弹幕记录 联网的电脑和顺手的浏览器,我用的Chrome Python3环境以及request模块,安装使用命令,换源比较快:...