python中用Beautifulsoup提取集搜客网站的信息
来源:互联网 发布:get music软件 编辑:程序博客网 时间:2024/05/21 17:34
1爬取集搜客网站上面的信息点击打开链接
2看下这个源代码
3使用正则表达式提取出来
# coding:utf8import urllib2import timefrom bs4 import BeautifulSoupclass YZW():#先是定义一个模块然后就是用来包含用到的函数 def __init__(self): self.user_agent='Mozilla/5.0 (Windows NT 6.1; WOW64)'#设置它的用户代理,模仿浏览器来访问 self.header={'User_Agent':self.user_agent}#利用header的字典来传入 def getHtml(url,page): try:#运用try except 函数 urls='http://www.gooseeker.com/cn/forum/7?page='+str(page)#如果要爬取多页,观察多页网站规律 page=urllib2.urlopen(urls) html=page.read() return html except urllib2.URLError, g:#如果出现URLError的错误,会执行以下代码 if hasattr (g,"reason"): print u'loding error', g.reason return None def getitem(self): for i in range(12): html=self.getHtml(i) time.sleep(1) soup=BeautifulSoup(html,"html.parser") Data=soup.find_all('tr',class_='odd')#观察自己要提取信息的标签,然后来提取信息 for item in Data: lists = item.get_text("|")#得到其中的文本,然后就是用 | 来代替以前的分割 lists = lists.split('|') try: print lists[0],lists[1],lists[3] except: print 'None' Data=soup.find_all('tr',class_='even') for item in Data: lists = item.get_text("|") lists = lists.split('|')4然后看下这个运行结果
0 0
- python中用Beautifulsoup提取集搜客网站的信息
- python中用beautifulSoup 安装
- python中用beautifulSoup 安装
- python爬虫里信息提取的核心方法: Beautifulsoup、Xpath和正则表达式
- Python爬取百度百科,BeautifulSoup提取关键信息
- Python网络爬虫与信息提取(二) BeautifulSoup库
- MOOC-Python网络爬虫与信息提取-第二周 BeautifulSoup库入门与信息提取方法
- python+beautifulsoup+smtp爬取学院网站的信息公告+邮件发送
- Python爬虫---数据的提取---正则/Xpath/beautifulsoup--正则
- python提取piazza的信息
- 使用Python+selenium+BeautifulSoup抓取动态网页的关键信息
- Python爬虫---提取数据(2)--beautifulsoup
- beautifulsoup提取所有<a>标签内容 Python
- ArcMap中用python的split方法提取字段的值
- python BeautifulSoup的安装
- python的BeautifulSoup用法
- Python的BeautifulSoup安装
- python爬虫信息提取的一般方法
- caffe_SCIR--预测函数改为对称性
- ubuntu14.04.1上安装mongodb3.4
- 缓和曲线04四次两段曲线
- 该做什么?该怎么做?如何为自己的人生负责
- 高性能Mysql主从架构的复制原理及配置详解
- python中用Beautifulsoup提取集搜客网站的信息
- 数据结构-C++实现(一):数组链表
- jenkins迁移job插件 job-import插件
- ECMAScript6(ES6)标准之数组Array扩展方法
- 如何在Ubuntu系统下安装使用LaTeX
- 缓和曲线05五次抛物线
- springMVC源码分析--AbstractHandlerMapping(二)
- 三个怪兽和三个和尚过河java版
- 网页设计