se162xg / notes

1 stars 1 forks source link

Chrome&Selenium #21

Open se162xg opened 4 years ago

se162xg commented 4 years ago
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb
// https://chromedriver.chromium.org/downloads
se162xg commented 4 years ago
import warnings
from selenium.webdriver import Chrome, ChromeOptions

warnings.filterwarnings(action='ignore', module='selenium')

opt = ChromeOptions()
opt.add_argument('--headless')
opt.add_argument('--disable-gpu')
opt.add_argument('--allow-running-insecure-content')
opt.add_argument("service_args=['–ignore-ssl-errors=true', '–ssl-protocol=TLSv1']")
opt.add_experimental_option('excludeSwitches', ['enable-automation'])
opt.add_argument('--blink-settings=imagesEnabled=false')

browser = Chrome(chrome_options=opt)
browser.get('https://example.com')
sleep(5)
print(browser.page_source)
browser.quit()
se162xg commented 4 years ago
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
capabilities = DesiredCapabilities.CHROME
capabilities["goog:loggingPrefs"] = {"performance": "ALL"}
browser = Chrome(chrome_options=opt, desired_capabilities=capabilities)
for entry in browser.get_log('performance'):
    tmp = json.loads(entry['message'])
    if tmp['message']['method']=='Network.requestWillBeSent':
        print(tmp['message']['params']['request']['method'], tmp['message']['params']['request']['url'])