Beautifulsoup关于find的测试
from bs4 import BeautifulSoup
import requests
url='https://book.douban.com/subject_search?search_text=golang&cat=1001'
html=requests.get(url).text
# print(html)
soup=BeautifulSoup(html,'lxml')
booknames=soup.findAll('li',{'class':'subject-item'}) #查找标签
bookname=[]
chubanshe=[]
year=[]
pingjia_price=[]
for name in booknames:
a=name.get_text().replace(' ','').replace('\n','').split('/') #get_text方法
# print(a)
bookname.append(a[0])
chubanshe.append(a[1])
year.append(a[2])
pingjia_price.append(a[-1])
print(bookname)
print(chubanshe)
print(year)
print(pingjia_price)
beautifulsoup中的find和findall参数
findAll(tag,attributes,recursive,text,limit,keywords)
findAll(tag,attributes,recursive,text,keywords)
分别代表,标签,传入字典形式的标签属性,递归开关,文本匹配数量,limitpi匹配前多少项目,关键字参数
一般来说,使用,第一个和最后的关键字参数便可,其他都是默认参数,
Beautifulsoup关于find的测试的更多相关文章
- beautifulsoup测试
import re from bs4 import BeautifulSoup html_doc = """ <html><head><ti ...
- BeautifulSoup库测试代码
import requests from bs4 import BeautifulSoup import time headers={ #'User-Agent':'Nokia6600/1.0 (3. ...
- Python爬虫小白入门(三)BeautifulSoup库
# 一.前言 *** 上一篇演示了如何使用requests模块向网站发送http请求,获取到网页的HTML数据.这篇来演示如何使用BeautifulSoup模块来从HTML文本中提取我们想要的数据. ...
- BeautifulSoup :功能使用
# -*- coding: utf-8 -*- ''' # Author : Solomon Xie # Usage : 测试BeautifulSoup一些用法及容易出bug的地方 # Envirom ...
- 使用Beautifulsoup爬取药智网数据
使用Beautifulsoup模块爬取药智网数据 Tips:1.爬取多页时,先用一页的做测试,要不然ip容易被封 2.自己常用的处理数据的方法: reg=re.compile('正则表达式') dat ...
- python+urllib+beautifulSoup实现一个简单的爬虫
urllib是python3.x中提供的一系列操作的URL的库,它可以轻松的模拟用户使用浏览器访问网页. Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能 ...
- Python-Windows下安装BeautifulSoup和requests第三方模块
http://blog.csdn.net/yannanxiu/article/details/50432498 首先给出官网地址: 1.Request官网 2.BeautifulSoup官网 我下载的 ...
- BeautifulSoup获取指定class样式的div
如何获取指定的标签的内容是解析网页爬取数据的必要手段,比如想获取<div class='xxx'> ...<div>这样的div标签,通常有三种办法, 1)用字符串查找方法,然 ...
- Python -- BeautifulSoup的学习使用
BeautifulSoup4.3 的使用 下载和安装 # 下载 http://www.crummy.com/software/BeautifulSoup/bs4/download/ # 解压后 使用r ...
随机推荐
- vue之node.js的简单介绍
一.什么是node.js? 它是可以运行JavaScript的服务平台,可以吧它当做一门后端程序,只是它的开发语言是JavaScript 二.安装 1.node.js的特性: - 非阻塞IO模型 - ...
- laravel 不理解的call方法
返回结果: 原来是调用同控制器的这四个方法之一...vendor\zhiyicx\plus-question\src\API2\Controllers\UserQuestionController.p ...
- Spring Boot的Listener机制的用法和实现原理详解
之前在介绍了在spring-boot启动过程中调用runner的原理,今天我们介绍另外一种可以实现相似功能的机制:spring-boot的Listener机制. 通过注册Listener,可以实现对于 ...
- python操作注册表
#注册表操作 # -*- coding: utf-8 -*- import win32api import win32con #打开注册表:传主键化值,子键值,操作方法(win32con.KEY_AL ...
- RabbitMQ在java中基础使用
RabbitMQ相关术语: 1.Broker:简单来说就是消息队列服务器实体. 2.Exchange:消息交换机,它指定消息按什么规则,路由到哪个队列. ...
- hive sql常用整理-hive引擎设置
遇到个情况,跑hive级联insert数据报错,可以尝试换个hive计算引擎 hive遇到FAILED: Execution Error, return code 2 from org.apache. ...
- 史上最简单的SpringCloud教程 | 第五篇: 路由网关(zuul)
在微服务架构中,需要几个基础的服务治理组件,包括服务注册与发现.服务消费.负载均衡.断路器.智能路由.配置管理等,由这几个基础组件相互协作,共同组建了一个简单的微服务系统.一个简答的微服务系统如下图: ...
- Python sendmail
#coding:utf- #强制使用utf-8编码格式 import smtplib #加载smtplib模块 from email.mime.text import MIMEText from em ...
- java.lang.NoClassDefFoundError: javax/servlet/AsyncListener解决方案
问题:spring3.2的架构在tomcat6.0中无法正常启动,抛出java.lang.NoClassDefFoundError: javax/servlet/AsyncListener错误 原因: ...
- 使用python调用shell判断当前进程是否存在
使用subprocess模块判断当前进程是否存在 #! /usr/bin/env python import subprocess res = subprocess.Popen(r'ps -ef |g ...