药监局 selenium
时间: 2023-11-06 12:06:38 浏览: 81
药监局 selenium 是通过使用selenium库来获取药监管理局网站数据的方法之一。通过使用selenium库,可以模拟浏览器行为,实现自动化网页操作,从而获取所需的数据。在使用selenium进行数据获取时,通常需要先配置相应的浏览器驱动程序,然后通过指定驱动程序的路径来创建浏览器对象。接下来,可以使用浏览器对象执行一系列操作,如打开指定的网页、点击按钮、填写表单等,最后获取所需的数据。
对于使用selenium获取药监局网站数据的具体步骤和示例代码如下:
1. 安装selenium库和相应的浏览器驱动程序(如Firefox驱动程序)。
2. 导入selenium库和time模块。
3. 使用webdriver类创建浏览器对象,并指定浏览器驱动程序的路径。
4. 使用浏览器对象的get()方法打开目标网页。
5. 可选:使用time模块的sleep()方法等待页面加载完成。
6. 使用浏览器对象的find_element_by_XXX()方法定位到所需的元素。
7. 可选:使用浏览器对象的click()方法、send_keys()方法等操作元素。
8. 使用浏览器对象的page_source属性获取页面源代码。
9. 可选:使用浏览器对象的quit()方法关闭浏览器。
以下是一个示例代码,用于使用selenium获取药监局网站数据:
import time
from selenium import webdriver
driver = webdriver.Firefox(executable_path='./driver/geckodriver.exe')
driver.get("https://www.yaojiaju.cn/")
time.sleep(2)
html = driver.page_source
print(html)
driver.quit()
以上代码通过创建一个Firefox浏览器对象,打开了药监局网站,并获取了页面的源代码。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)