当前位置:网站首页>robobrowser的简单使用
robobrowser的简单使用
2022-07-28 18:05:00 【华为云】
robobrowser简单介绍:
简单来说,robobrowser是一个轻量级的浏览器,自动测试库,和selenium类似,但运行比selenium更为隐蔽,因为它不会打开浏览器页面。RoboBrowser,Your friendly neighborhood web scraper!由纯 Python 编写;
项目地址:打开
安装
推荐使用pip方式安装,简单!
robobrowser库依赖其他库,bs4,lxml,所以两个库都要安装;
打开命令行窗口,输入代码:
pip install lxml
pip install bs4
pip install robobrowser
等待安装成功;
验证一下:
打开命令行窗口,输入python进行解释器窗口;
输入代码:import robobrowser
如果提示以下错误
File “D:\python3.8\lib\site-packages\robobrowser\browser.py”, line 8, in <module>
from werkzeug import cached_property
ImportError: cannot import name ‘cached_property’ from ‘werkzeug’ (D:\python3.8\lib\site-packages\werkzeug_init_.py)

需要打开文件:
D:\python3.8\lib\site-packages\werkzeug_init_.py
输入from werkzeug.utils import cached_property即可修复
from .serving import run_simple as run_simplefrom .test import Client as Clientfrom .wrappers import Request as Requestfrom .wrappers import Response as Response#显示引入from werkzeug.utils import cached_property # 这是引入的包 __version__ = "2.1.2"简单使用;
模拟百度搜索,提交表单:
home_url = 'http://www.baidu.com' # parser: 解析器,HTML parser; used by BeautifulSoup# 官方推荐:lxmlrb = RoboBrowser(history=True, parser='lxml') # 打开目标网站rb.open(home_url)#print(rb.parsed())# 获取表单对象bd_form = rb.get_form()print(bd_form)bd_form['wd'].value = "robobrowser"# 提交表单,模拟一次搜索rb.submit_form(bd_form)#print(rb.parsed())sleep(1)# 查看结果result_elements = rb.select(".result")print(result_elements)以上获取到的结果,可以使用
from bs4 import BeautifulSoup
进行解析;
如获取标题,链接等;
for index, element in enumerate(result_elements):
title = element.find(“a”).text
href = element.find(“a”)[‘href’]
其他操作
跳转链接rb.follow_link(first_href)获取历史print(rb.url)更多的操作,可以参考官方文档;
边栏推荐
- [C language] summary of methods for solving the greatest common divisor
- Intermediate soft test (system integration project management engineer) high frequency test site
- Two methods to judge the size end
- JVM(二十四) -- 性能监控与调优(五) -- 分析GC日志
- Tencent cloud deployment lamp_ Experience of building a station
- Saltstack advanced
- 党员故事|李青艾用漫画带动农民增收致富
- 利用STM32的HAL库驱动1.54寸 TFT屏(240*240 ST7789V)
- adb remount of the / superblock failed: Permission denied
- 一文读懂如何部署具有外部数据库的高可用 K3s
猜你喜欢

adb remount of the / superblock failed: Permission denied

Article translation software - batch free translation software supports major translation interfaces
![[wechat applet development] page navigation and parameter transmission](/img/10/76b6592fa9e71073831887c4fb6da9.png)
[wechat applet development] page navigation and parameter transmission

Implementation of markdown editor in editor.md

Overcome the "fear of looking at teeth", and we use technology to change the industry

A chip company fell in round B

私有化部署的即时通讯平台,为企业移动业务安全保驾护航

2. Floating point number, the difference between float and double in C language and how to choose them

Cloud computing notes part.1 - system management
![[C language] print pattern summary](/img/48/d8ff17453e810fcd9269f56eda4d47.png)
[C language] print pattern summary
随机推荐
[C language] Gobang game [array and function]
Two methods to judge the size end
Basic knowledge of communication network 01
Why is there no log output in the telnet login interface?
Cell review: single cell methods in human microbiome research
Design of air combat game based on qtgui image interface
[C language] Pointer advanced knowledge points
Andorid system layout, values, drawable adaptation
6. Functions of C language, why functions are needed, how functions are defined, and the classification of functions
KPMG China: insights into information technology audit projects of securities fund management institutions
Labelme (I)
Implementation of markdown editor in editor.md
[C language] Fibonacci sequence [recursion and iteration]
Token verification program index.php when configuring wechat official account server
Deploy LNMP automatically with saltstack
[C language] Pointer elementary knowledge points
Article translation software - batch free translation software supports major translation interfaces
[C language] print pattern summary
一文读懂如何部署具有外部数据库的高可用 K3s
Advanced notes (Part 2)