homedir = getenv('HOME')
options.add_argument('--user-data-dir="{}"'.format(homedir))
options.add_argument('--remote-debugging-port=9222')
HOME
, подправьте FROM python:3.8.2-alpine
ARG FILENAME_ARG
ENV FILENAME $FILENAME_ARG
# time on alpine does not recognize a long --format argument
CMD time -f '%U' python temp/${FILENAME} 2>&1
FROM python:3.8.2-alpine
ARG FILENAME_ARG
ENV FILENAME $FILENAME_ARG
ENV TIME '%u'
CMD time python temp/${FILENAME} 2>&1
man time
TIME(1) General Commands Manual TIME(1)
NAME
time - run programs and summarize system resource usage
%U Total number of CPU-seconds that the process spent in user
mode.
...
%R Number of minor, or recoverable, page faults.
%R
&>
#!/usr/bin/env python3
from __future__ import print_function
import sys
from time import sleep
print('print to stdout')
sleep(2)
print('print to stderr', file = sys.stderr)
python w.py &>w.log &
[1] 4591
[1]+ Done python w.py &> w.log
cat w.log
print to stderr
print to stdout
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36")
text = 'Continue to Discord'
text = 'Принять приглашение'
driver.find_element_by_xpath('//button/div[contains(text(), "{}")]'.format(text))
{"method":"xpath","selector":"//button/div[contains(text(), "Принять приглашение")]"}
from cyrtranslit import to_latin
from selenium import webdriver
from selenium.webdriver.firefox.webdriver import WebDriver
def waittest:
def __init__(self, selector, value):
self.selector = selector
self.value = value
def __call__(self, driver):
element = driver.find_element_by_css_selector(self.selector)
text = element.text
print('checking text: "{}" against "{}"'.format(to_latin(text, 'ru'), self.value))
if to_latin(text, 'ru') == self.value:
return element
else:
return None
text = to_latin('Принять приглашение', 'ru')
element = WebDriverWait(driver, 10).until( waittest("button[class *= 'button']", text))
from __future__ import print_function
import re
from xml.dom import minidom
xmldoc = minidom.parseString(data.strip())
nodes = xmldoc.getElementsByTagName('cpe')
print(nodes[0].firstChild.data)
nodes = xmldoc.getElementsByTagName('address')
print (nodes[0].attributes['addr'].value)
cpe:/h:hp:p2000_g3
45.33.49.119
Desktop\test.ps1:
write-output 'test'
test.py:
# -*- coding: iso-8859-1 -*-
import subprocess, sys
p = subprocess.Popen(["powershell.exe",
"C:\\Users\\<USER>\\Desktop\\test.ps1"],
stdout=sys.stdout)
p.communicate()
python test.py
test
element = driver.execute_script("return document.querySelector('form table tr:first-child td:nth-child(2) b')")
value = element.text
url = 'https://www.youtube.com/'
title = 'YouTube'
driver = webdriver.Chrome()
driver.get(url)
try:
# https://selenium-python.readthedocs.io/waits.html
WebDriverWait(driver,10).until(EC.title_contains(title))
except (NoAlertPresentException, TimeoutException) as e:
print('page was not shown: {0}'.format(e))
finally:
driver.quit()
disired_capabilities = DesiredCapabilities.CHROME
disired_capabilities['loggingPrefs'] = {
'browser':'ALL'
}
driver = webdriver.Chrome(executable_path = chromedriver_path, desired_capabilities = disired_capabilities)
[
'//a[contains(@href,"{}")]'.format(url_fragment.lower()),
'//a[contains(translate(@href, "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), "{}")]'.format(url_fragment.upper())
]
length = len(xpaths)
for cnt in range(length):
xpath = xpaths[cnt]
print('# try {}'.format(cnt))
element = None
try:
element = driver.find_element_by_xpath(xpath)
except InvalidSelectorException, e:
print('Exception (ignored): {}'.format(e))
pass
except NoSuchElementException, e:
print('Exception (ignored): {0}'.format(e))
pass
if element != None:
print('Found via {}'.format(xpath))
print(element.get_attribute('outerHTML'))
else:
print('Failed via {}'.format(xpath))