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

  • 相关阅读:
    Codeforces 959 E Mahmoud and Ehab and the xor-MST
    LightOj 1336 Sigma Function
    某考试 T1 sigfib
    [BOI2007] Sequence
    UOJ 41. 矩阵变换
    [BOI2007] Mokia
    SPOJ 26108 TRENDGCD
    bzoj3545: [ONTAK2010]Peaks
    bzoj3910: 火车
    bzoj1185: [HNOI2007]最小矩形覆盖
  • 原文地址:https://www.cnblogs.com/hkingsp/p/15015095.html
Copyright © 2011-2022 走看看