arm树莓派Raspbian 下安装selenium+chrome
arm树莓派Raspbian 下安装selenium+chrome
安装selenium
pip3 install selenium
安装chromedriver
sudo apt-get install chromium-chromedriver
查看安装路径
dpkg -L chromium-chromedriver
3 import time
4 from datetime import datetime
5
6 from selenium import webdriver
7 from selenium.webdriver.chrome.options import Options
8
9 #from dbfs.dalog import log_print as print
10
11
12 class WebDriver(object):
- 13 def __init__(self):
- 14 self._options = Options()
2 15 self._options.add_argument('--headless')
| 16
| 17
| 18 def get_web(self, url):
- 19 content = ''
2 20 st = datetime.now()
2 21 with webdriver.Chrome(chrome_options=self._options) as driver:
2 22 print(">>>>> WebDriverChrom {} GET: {}\r\n".format(st, url))
2 23 driver.get(url)
2 24 time.sleep(10)
2 25 content = driver.page_source
2 26 et = datetime.now()
2 27 print("<<<<< {} UseTime: {}\r\n <<< RECV {}".format(et, (et-st).total_seconds(), True))
2 28 #print(content, driver.current_url)
2 29 return dict(status=True, content=content, url=driver.current_url)
30
31
32 webget = WebDriver().get_web
33
34
35 __all__ = ['webget']
36
37
38 if __name__ == '__main__':
- 39 url = 'https://kuaibao.qq.com/s/20181224A0R6M300?refer=kb_news&omgid=1e32392c176538c757f9132b230e79a2&chlid=5915889&atype=0'
| 40 webget(url)
Chromium
确保你已经安装了 chromium。
chromium 安装之后的目录可以使用 ls /usr/lib/chromium-browser 查看。
使用 sudo apt search chromedriver 可以惊喜地发现在 APT 中就可以安装 chromium 驱动。
使用 sudo apt install -y chromium-chromedriver 即可安装.
使用方式:
$ python3
...msg...
>>> from selenium import webdriver
>>> browser = webdriver.Chrome(
... executable_path='/usr/lib/chromium-browser/chromedriver')
>>> browser.get('baidu.com')
>>> browser.quit()
>>>
>>> exit()