当前位置:网站首页>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)更多的操作,可以参考官方文档;
边栏推荐
- 8. Compilation errors of C language and Chinese explanation
- What is the process of swing event processing?
- [网络]跨区域网络的通信学习路由表的工作原理
- Implementation of strstr in C language
- A chip company fell in round B
- XOR operation and its usage
- Intermediate soft test (system integration project management engineer) high frequency test site
- C language function
- [C language] random number generation and `include < time. H > 'learning
- 2022年下半年系统集成项目管理工程师认证8月20日开班
猜你喜欢
![[C language] simulation implementation of strlen (recursive and non recursive)](/img/73/e92fe714515491f1ea366d6924c9ec.png)
[C language] simulation implementation of strlen (recursive and non recursive)

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

中国能否在元宇宙的未来发展中取得突破,占领高地?

3、 Are formal and actual parameters in a programming language variables?

Deploy ZABBIX automatically with saltstack

Kubeedge releases white paper on cloud native edge computing threat model and security protection technology

Function fitting based on MATLAB

Cdga | how can the industrial Internet industry do a good job in data governance?

Theoretical knowledge of digital image (I) (personal analysis)

9. Pointer of C language (2) wild pointer, what is wild pointer, and the disadvantages of wild pointer
随机推荐
通信网络基础知识01
7. Functions of C language, function definitions and the order of function calls, how to declare functions, prime examples, formal parameters and arguments, and how to write a function well
软考高级考试中有五大证书,哪个更值得考?
Use of strtok and strError
Design of air combat game based on qtgui image interface
Source code analysis of scripy spider
editor.md中markdown编辑器的实现
Basic knowledge of C language
Find the memory occupied by the structure
XOR operation and its usage
Cdga | how can the industrial Internet industry do a good job in data governance?
软考中级(系统集成项目管理工程师)高频考点
Prometheus deployment
Using Lex (Flex) to generate lexical analyzer of PL language
Leetcode day4 the highest paid employee in the Department
Servlet learning notes
Data system of saltstack
[C language] summary of methods for solving the greatest common divisor
Return and job management of saltstack
Common modules of saltstack