zoukankan      html  css  js  c++  java
  • python run javascript in ubuntu

    1. download and download chrome
    wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
    sudo apt install ./google-chrome-stable_current_amd64.deb

    2. check chrome version and install corresponding chromedriver
    chromedriver:
    wget https://sites.google.com/a/chromium.org/chromedriver/downloads
    sudo unzip chromedriver_linux64.zip
    sudo cp chromedriver /usr/bin -v

    3. install splinter in python
    pip3 install splinter

    4. source code:
    #!/usr/bin/python3
    # -*- coding:utf-8 -*-
    import requests
    from splinter import Browser
    from selenium.webdriver.chrome.options import Options
    chrome_options = Options()
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-dev-shm-usage')
    br = Browser('chrome',options=chrome_options)
    print(br.evaluate_script("4+4") == 8)


    issue 1:
    chrome cannot be started by click chrome app:
    solution:
    rm ~/.config/google-chrome/*

    issue 2:
    chrome is no longer running so ChromeDriver is assuming that Chrome has crashed
    solution:
    1.install corresponding chrome driver to chrome webserver
    https://sites.google.com/a/chromium.org/chromedriver/downloads
    2. Make sure that --no-sandbox option is the first option in chromeoption
    chrome_options = Options()
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--headless')

  • 相关阅读:
    Java 重写(Override)与重载(Overload)
    Java 继承
    Java 异常处理
    Java Scanner 类
    Java 流(Stream)、文件(File)和IO
    Java 方法
    Java 正则表达式
    Beta冲刺——代码规范、冲刺任务与计划
    Beta冲刺——凡事预则立
    Beta冲刺——问题总结博客(事后诸葛亮和组员交换事宜)
  • 原文地址:https://www.cnblogs.com/hkingsp/p/15015095.html
Copyright © 2011-2022 走看看