python简单爬虫 及 beautifulSoup简单用法
2017-02-14 19:28
603 查看
主要是在这里看到的:
http://www.jb51.net/article/65287.htm
爬取电影天堂的磁力链接
#-*- coding: utf-8 -*-
import urllib.request
from bs4 import BeautifulSoup
import re
url='http://www.dytt8.net/index.htm'
res=urllib.request.urlopen(url).read()
html=res.decode('gbk')
#print(html)
soup = BeautifulSoup(html,"html.parser")
res = soup.find_all(href=re.compile('/html/gndy/dyzz/2017'))
for each in res:
each='http://www.dytt8.net/'+each['href']
res2=urllib.request.urlopen(each)
html2=res2.read().decode('gbk')
soup2 = BeautifulSoup(html2,"html.parser")
data = soup2.find_all(href=re.compile('ftp://'))
print(data[0]['href'])
创建 beautifulsoup 对象
soup = BeautifulSoup(html)
find_all() 用法 返回的是一个列表
A.name参数 = name 参数可以查找所有名字为 name 的tag,字符串对象会被自动忽略掉
1.传字符串
2.传正则表达式
3.传列表
4.传True (没用过)
5.传方法(没用过)
B.keyword参数 = 搜索时会把该参数当作指定名字tag的属性来搜索
C.text参数返回的不是tag
soup.find_all(text="Elsie")
# [u'Elsie']
soup.find_all(text=["Tillie", "Elsie", "Lacie"])
# [u'Elsie', u'Lacie', u'Tillie']
soup.find_all(text=re.compile("Dormouse"))
[u"The Dormouse's story", u"The Dormouse's story"]
http://www.jb51.net/article/65287.htm
爬取电影天堂的磁力链接
#-*- coding: utf-8 -*-
import urllib.request
from bs4 import BeautifulSoup
import re
url='http://www.dytt8.net/index.htm'
res=urllib.request.urlopen(url).read()
html=res.decode('gbk')
#print(html)
soup = BeautifulSoup(html,"html.parser")
res = soup.find_all(href=re.compile('/html/gndy/dyzz/2017'))
for each in res:
each='http://www.dytt8.net/'+each['href']
res2=urllib.request.urlopen(each)
html2=res2.read().decode('gbk')
soup2 = BeautifulSoup(html2,"html.parser")
data = soup2.find_all(href=re.compile('ftp://'))
print(data[0]['href'])
创建 beautifulsoup 对象
soup = BeautifulSoup(html)
find_all() 用法 返回的是一个列表
A.name参数 = name 参数可以查找所有名字为 name 的tag,字符串对象会被自动忽略掉
1.传字符串
2.传正则表达式
3.传列表
4.传True (没用过)
5.传方法(没用过)
B.keyword参数 = 搜索时会把该参数当作指定名字tag的属性来搜索
C.text参数返回的不是tag
soup.find_all(text="Elsie")
# [u'Elsie']
soup.find_all(text=["Tillie", "Elsie", "Lacie"])
# [u'Elsie', u'Lacie', u'Tillie']
soup.find_all(text=re.compile("Dormouse"))
[u"The Dormouse's story", u"The Dormouse's story"]
相关文章推荐
- python爬虫--BeautifulSoup的简单用法
- python beautifulsoup简单用法
- Python爬虫辅助库BeautifulSoup4用法精要
- [python爬虫] BeautifulSoup和Selenium简单爬取知网信息测试
- Python:第三方模块BeautifulSoup的安装及简单用法
- python简单爬虫,Beautifulsoup4解析,爬取直播吧部分热门新闻及链接
- 【Python3.6爬虫学习记录】(二)使用BeautifulSoup爬取简单静态网页文章
- Python---BeautifulSoup 简单的爬虫实例
- 一个简单的不用cookie的人人网状态爬取的python爬虫,使用beautifulsoup
- python BeautifulSoup的简单用法
- Python爬虫--beautifulsoup 4 用法
- BeautifulSoup与正则_简单爬虫python3实现
- python爬虫【记录】BeautifulSoup 的用法遍历学习
- Python爬虫BeautifulSoup用法(1)
- Python---BeautifulSoup 简单的爬虫实例
- python爬虫系列(2)—— requests和BeautifulSoup库的基本用法
- 【爬虫】python之BeautifulSoup用法
- 使用python语言结合beautifulsoup编写简单的网络爬虫
- Python爬虫-BeautifulSoup4 库的一些用法
- 简单爬虫python实现02——BeautifulSoup的使用