• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python使用BeautifulSoup分析网页信息的方法

python使用BeautifulSoup分析网页信息的方法

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python beautifulsoup,python beautiful,beautiful4包python,beautifulsoup,beautifulsoup安装等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了python使用BeautifulSoup分析网页信息的方法。分享给大家供大家参考。具体如下:

这段python代码查找网页上的所有链接,分析所有的span标签,并查找class包含titletext的span的内容
import urllib2

#specify the url you want to query
url = "http://www.python.org"

#Query the website and return the html to the variable 'page'
page = urllib2.urlopen(url)

#import the Beautiful soup functions to parse the data returned from the website
from BeautifulSoup import BeautifulSoup

#Parse the html in the 'page' variable, and store it in Beautiful Soup format
soup = BeautifulSoup(page)

#to print the soup.head is the head tag and soup.head.title is the title tag
print soup.head
print soup.head.title

#to print the length of the page, use the len function
print len(page)

#create a new variable to store the data you want to find.
tags = soup.findAll('a')

#to print all the links
print tags

#to get all titles and print the contents of each title
titles = soup.findAll('span', attrs = { 'class' : 'titletext' })
for title in allTitles:
print title.contents</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • Python利用Beautiful Soup模块创建对象详解
  • Python利用Beautiful Soup模块修改内容方法示例
  • Python利用Beautiful Soup模块搜索内容详解
  • Python利用Beautiful Soup模块创建对象详解
  • Python利用Beautiful Soup模块修改内容方法示例
  • Python使用BeautifulSoup库解析HTML基本使用教程
  • python基于BeautifulSoup实现抓取网页指定内容的方法
  • Python中使用Beautiful Soup库的超详细教程
  • Python中使用Beautiful Soup库的超详细教程
  • python使用BeautifulSoup分页网页中超链接的方法

相关文章

  • python为tornado添加recaptcha验证码功能
  • Python使用面向对象方式创建线程实现12306售票系统
  • Pycharm学习教程(1) 定制外观
  • Python中在脚本中引用其他文件函数的实现方法
  • Python中Collection的使用小技巧
  • Python制作Windows系统服务
  • windows 10下安装搭建django1.10.3和Apache2.4的方法
  • wxPython 入门教程
  • python Django批量导入数据
  • Python写的Tkinter程序屏幕居中方法

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python中asyncore异步模块的用法及实现httpclient的实例
    • python检测lvs real server状态
    • Python实现的简单算术游戏实例
    • python实现ftp客户端示例分享
    • Python的Flask站点中集成xhEditor文本编辑器的教程
    • python检测远程端口是否打开的方法
    • Python安装第三方库及常见问题处理方法汇总
    • videocapture库制作python视频高速传输程序
    • Python操作MongoDB数据库PyMongo库使用方法
    • 详解python脚本自动生成需要文件实例代码

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有