当前位置:网站首页>Simple use of robobrowser
Simple use of robobrowser
2022-07-28 20:13:00 【Hua Weiyun】
robobrowser Brief introduction :
Simply speaking ,robobrowser Is a lightweight browser , Automatic test library , and selenium similar , But the operation ratio selenium More hidden , Because it won't open the browser page .RoboBrowser,Your friendly neighborhood web scraper! From pure Python To write ;
Project address : open
install
Recommended pip Way to install , Simple !
robobrowser Libraries depend on other libraries ,bs4,lxml, So both libraries should be installed ;
Open the command line window , Enter the code :
pip install lxml
pip install bs4
pip install robobrowser
Wait for the installation to succeed ;
Check it out :
Open the command line window , Input python Go to the interpreter window ;
Enter the code :import robobrowser
If the following error is prompted
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)

You need to open the file :
D:\python3.8\lib\site-packages\werkzeug_init_.py
Input from werkzeug.utils import cached_property You can fix it
from .serving import run_simple as run_simplefrom .test import Client as Clientfrom .wrappers import Request as Requestfrom .wrappers import Response as Response# Show the introduction from werkzeug.utils import cached_property # This is the package introduced __version__ = "2.1.2"Easy to use ;
Simulating Baidu search , Submit Form :
home_url = 'http://www.baidu.com' # parser: Parser ,HTML parser; used by BeautifulSoup# The official recommendation :lxmlrb = RoboBrowser(history=True, parser='lxml') # Open the target website rb.open(home_url)#print(rb.parsed())# Get form object bd_form = rb.get_form()print(bd_form)bd_form['wd'].value = "robobrowser"# Submit Form , Simulate a search rb.submit_form(bd_form)#print(rb.parsed())sleep(1)# View results result_elements = rb.select(".result")print(result_elements)The results obtained above , have access to
from bs4 import BeautifulSoup
To analyze ;
For example, get the title , Links, etc. ;
for index, element in enumerate(result_elements):
title = element.find(“a”).text
href = element.find(“a”)[‘href’]
Other operating
Jump Links rb.follow_link(first_href) Get history print(rb.url)More operations , Please refer to the official documents ;
边栏推荐
- Information management system and games based on C language
- Prometheus deployment
- 河北:稳粮扩豆助力粮油生产提质增效
- In the second half of 2022, the system integration project management engineer certification starts on August 20
- [C language] random number generation and `include < time. H > 'learning
- 1. C language variable type, global variable, local variable
- C language - pointer
- WFST decoding process
- Read how to deploy highly available k3s with external database
- lattice
猜你喜欢

党员故事|李青艾用漫画带动农民增收致富
![[C language] Hanoi Tower problem [recursion]](/img/d8/ff66928c2bc2ad906e38a360a8cf94.png)
[C language] Hanoi Tower problem [recursion]

There is a 'single quotation mark' problem in the string when Oracle inserts data

Getting started with enterprise distributed crawler framework

数字滤波器设计——Matlab
![最大交换[贪心思想&单调栈实现]](/img/ad/8f0914f23648f37e1d1ce69086fd2e.png)
最大交换[贪心思想&单调栈实现]

Reverse string

Basic knowledge of communication network 01

The results of the second quarter online moving people selection of "China Internet · moving 2022" were announced

A chip company fell in round B
随机推荐
“中国网事·感动2022”二季度网络感动人物评选结果揭晓
利用STM32的HAL库驱动1.54寸 TFT屏(240*240 ST7789V)
Read how to deploy highly available k3s with external database
adb remount of the / superblock failed: Permission denied
软考中级(系统集成项目管理工程师)高频考点
Circular linked list OJ question
Saltstack advanced
Usage of const and assert
C language function
[C language] Fibonacci sequence [recursion and iteration]
[C language] initial C language reflection and summary
C language array and bubble sort
Implementation of strstr in C language
2、 Relationship between software operation and memory
Store and guarantee rancher data based on Minio objects
1. C language variable type, global variable, local variable
Zfoo adds routes similar to mydog
[C language] guessing numbers game [function]
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
How to use pycharm to quickly create a flask project