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')

  • 相关阅读:
    utf8编码和中文不能解码问题解决
    python环境的安装配置
    repo同一个仓的同一个changeId的提交
    Jenkins pipeline之将命令的运行结果赋值给变量
    repo和git常用的命令和场景
    docker 安装rabbitmq
    docker的一些概念
    mysql数据库sql优化原则
    数据库优化02
    MySQL数据库优化总结
  • 原文地址:https://www.cnblogs.com/hkingsp/p/15015095.html
Copyright © 2011-2022 走看看