import re
from bs4 import BeautifulSoup html_doc = """
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title"><b>The Dormouse's story</b></p> <p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</p> <p class="story">...</p>
"""
soup = BeautifulSoup(html_doc, 'html.parser') links = soup.find('a',href=re.compile(r'ill'))
print links.get_text()
links = soup.find('p',class_="title")
print links.get_text(),links.name

beautifulsoup测试的更多相关文章

  1. Beautifulsoup关于find的测试

    from bs4 import BeautifulSoup import requests url='https://book.douban.com/subject_search?search_tex ...

  2. BeautifulSoup库测试代码

    import requests from bs4 import BeautifulSoup import time headers={ #'User-Agent':'Nokia6600/1.0 (3. ...

  3. Python爬虫小白入门(三)BeautifulSoup库

    # 一.前言 *** 上一篇演示了如何使用requests模块向网站发送http请求,获取到网页的HTML数据.这篇来演示如何使用BeautifulSoup模块来从HTML文本中提取我们想要的数据. ...

  4. BeautifulSoup :功能使用

    # -*- coding: utf-8 -*- ''' # Author : Solomon Xie # Usage : 测试BeautifulSoup一些用法及容易出bug的地方 # Envirom ...

  5. 使用Beautifulsoup爬取药智网数据

    使用Beautifulsoup模块爬取药智网数据 Tips:1.爬取多页时,先用一页的做测试,要不然ip容易被封 2.自己常用的处理数据的方法: reg=re.compile('正则表达式') dat ...

  6. python+urllib+beautifulSoup实现一个简单的爬虫

    urllib是python3.x中提供的一系列操作的URL的库,它可以轻松的模拟用户使用浏览器访问网页. Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能 ...

  7. Python-Windows下安装BeautifulSoup和requests第三方模块

    http://blog.csdn.net/yannanxiu/article/details/50432498 首先给出官网地址: 1.Request官网 2.BeautifulSoup官网 我下载的 ...

  8. BeautifulSoup获取指定class样式的div

    如何获取指定的标签的内容是解析网页爬取数据的必要手段,比如想获取<div class='xxx'> ...<div>这样的div标签,通常有三种办法, 1)用字符串查找方法,然 ...

  9. Python -- BeautifulSoup的学习使用

    BeautifulSoup4.3 的使用 下载和安装 # 下载 http://www.crummy.com/software/BeautifulSoup/bs4/download/ # 解压后 使用r ...

随机推荐

  1. 链队列的C/C++实现

    #include <iostream> using namespace std; const int N = 10; typedef int ELEMTYPE; typedef struc ...

  2. 函数也是对象,本片介绍函数的属性、方法、Function()狗仔函数。

    1.arguments.length表示实参的个数. 2.arguments.callee.length表示形参个数. function test(a,b,c,d,e,f){ alert(argume ...

  3. 【BZOJ 1051】【HAOI 2006】受欢迎的牛

    tarjan缩点模板 #include<cstdio> #include<cstring> #include<algorithm> using namespace ...

  4. zabbix的使用

    1,zabbix运行流程 2功能特性 1数据收集 2灵活触发器 3高度可定制告警 4实时绘图功能 5web监控能力 6多种可视化展示 7历史数据存储 8配置容易 9API功能 10.......... ...

  5. Kernel Methods (4) Kernel SVM

    (本文假设你已经知道了hard margin SVM的基本知识.) 如果要为Kernel methods找一个最好搭档, 那肯定是SVM. SVM从90年代开始流行, 直至2012年被deep lea ...

  6. 解决npm install缓慢

    http://npm.taobao.org/ 使用淘宝提供的cnpm替代npm

  7. jquery-焦点定位追加内容

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. Linux的vim三种模式及命令

    一般模式:在Linux终端中输入"vim 文件名"就进入了一般模式,但不能输入文字.编辑模式:在一般模式下按i就会进入编辑模式,此时就可以写程式,按Esc可回到一般模式. 命令模式 ...

  9. 「c++小学期」实验题目及代码

    面向对象编程的C++,和平时做题用的C++还是有差距的.实验的题目都是小题目,就都做一下吧.(没放代码的为要验收的 实验一 简单C++程序设计 1.  猜价格游戏 编写C++程序完成以下功能: (1) ...

  10. ThinkPHP 3.2 Token表单令牌

    /home/conf/config.php 中配置 'TOKEN_ON'=>true, 'TOKEN_NAME'=>'__hash__', 'TOKEN_TYPE'=>'md5', ...