python urllib爬取百度云连接的实例代码
作者:baddog_ 时间:2022-03-07 19:06:28
翻看自己以前写的程序,发现写过一个爬取盘多多百度云资源的东西,完全是当时想看变形金刚才自己写的,而且当时第一次接触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)
来源:http://www.jianshu.com/p/5290b9273fe3?utm_source=tuicool&utm_medium=referral
标签:python,爬取,百度云
0
投稿
猜你喜欢
javascript实现数独解法
2023-10-17 17:18:28
Python如何定义有默认参数的函数
2023-08-05 14:38:30
情感的容器 被寄托了的QQ2010视觉设计
2010-02-03 14:51:00
python实现套接字创建
2021-09-09 05:12:04
python多线程semaphore实现线程数控制的示例
2022-12-29 18:31:40
怎么快速自学python
2023-06-25 19:19:32
Python字符串内置函数功能与用法总结
2022-08-17 00:29:29
Python对切片命名的实现方法
2023-09-30 09:43:15
python编写计算器功能
2022-10-29 14:07:33
一个JSP页面导致的tomcat内存溢出的解决方法
2023-06-30 04:14:41
Python实现的数据结构与算法之基本搜索详解
2021-07-25 03:47:44
python绘制带有色块的折线图
2022-08-11 07:01:58
30万条数据,搜索文本字段的各种方式对比
2010-05-02 10:17:00
Django uwsgi Nginx 的生产环境部署详解
2023-10-21 14:55:30
用CSS实现柱状图(Bar Graph)的方法(二)—基于表格元素的柱状图
2008-05-26 13:23:00
解决Jupyter无法导入已安装的 module问题
2022-05-13 07:14:18
详解Python中while无限迭代循环方法
2022-08-17 12:53:48
python数据类型中的字符串你了解多少
2023-10-07 19:55:19
利用python Selenium实现自动登陆京东签到领金币功能
2021-11-09 12:00:33
网站LOGO设计规范的思考--2.网络LOGO的设计
2007-10-14 11:02:00