python selenium phantomjs 百度搜索关键字并截屏
本例程通过模拟用户在百度首页输入关键字“金所炫”然后点击搜索,然后将网页截屏保存。
selenium : 是python模块库 需要用 pip install 安装,selenium版本2.48.0
phantomjs: 是无界面浏览器, 需要下载并解压到某个文件夹
1 from selenium import webdriver 2 import time 5 c = webdriver.PhantomJS(executable_path=r'C:\phantomjs-2.1.1-windows\bin\phantomjs.exe') 14 c.get('https://www.baidu.com') 16 c.find_element_by_id('kw').send_keys('金所炫') 17 c.find_element_by_id('su').click() 22 time.sleep(5) 23 c.save_screenshot('金.png') 25 print('--------Game over--------')

浙公网安备 33010602011771号