# Xpath надо написать самому
iframe = driver.find_element_by_xpath("//iframe")
driver.switch_to.frame(iframe)
driver.switch_to.default_content()
import requests
params = {
'name': 'Иванов Иван Иванович',
'numberOrInn': '1111111111',
}
response = requests.get('https://www.rgs.ru/api/agents/checkAgent', params=params)
# {"Status":"NotFound","ErrorCorrelationIds":[],"ErrorCode":null}
print(response.text)
Naive 13.342852999999998 seconds
Optimized 0.22429799999999744 seconds
Unique: [ True] Counts: [25000000]
import time
from time import process_time
import numpy
matrix = []
def naive():
from time import process_time
def create_matrix(n):
res_list = []
for i_ind in range(n):
res_list.append(list())
for j_ind in range(n):
res_list[i_ind].append(0)
return res_list
def get_counting_func(q_vector, v_vector):
q_matrix = [[*q_vector] for i in range(len(q_vector))]
v_matrix = [[i for j in range(len(v_vector))] for i in v_vector]
def t_func(i_start, i_len, j_start, j_len):
global matrix
for i in range(i_start, i_start + i_len):
for j in range(j_start, j_start + j_len):
matrix[i][j] = ((q_matrix[i][j]) ** 2 + (v_matrix[i][j]) ** 2) ** 0.5
return t_func
n_el = 5000
global matrix
matrix = create_matrix(n_el)
q_vect = [(i + 11) ** 2 for i in range(n_el)]
p_vect = [(i * 3 + 13) * 17 for i in range(n_el)]
counting_func = get_counting_func(q_vect, p_vect)
start_time = process_time()
counting_func(0, n_el, 0, n_el)
print('Naive ', process_time() - start_time, "seconds")
return matrix
def optimized():
start_time = process_time()
n_el = 5000
res = numpy.fromfunction(lambda i, j: (((i * 3 + 13) * 17) ** 2 + (j + 11) ** 4) ** 0.5, (n_el, n_el)
, dtype=numpy.float32)
print('Optimized ', process_time() - start_time, "seconds")
return res
if __name__ == '__main__':
first = naive()
second = optimized()
unique, counts = numpy.unique(numpy.isclose(second, numpy.array(first)), return_counts=True)
print(f'Unique: {unique} Counts: {counts}')
int(lvl) >= int(1)
lvl = int(await get_lvl(message))
if 0 <= lvl <= 9:
cost = 5000
elif 10 <= lvl <= 19:
cost = 10000
...
lvl = 23
costs = {
10: 5000,
20: 10000,
}
rounded_lvl = (lvl // 10) * 10
print(f'Rounded level: {rounded_lvl}')
cost = costs.get(rounded_lvl)
print(f'Cost: {cost}')
Rounded level: 20
Cost: 10000
Process finished with exit code 0
def all_args_is_none(args_list: list) -> bool:
return all(True if _ is None else False for _ in args_list)
def main():
if args.csv2parquet is not None:
csv_to_parquet(args.csv2parquet[0], args.csv2parquet[1])
if args.parquet2csv is not None:
parquet_to_csv(args.parquet2csv[0], args.parquet2csv[1])
if args.get_schema is not None:
print(get_schema(args.get_schema))
if all_args_is_none(args_list=[args.csv2parquet, args.parquet2csv, args.get_schema]):
print('type: python3 convert.py --help')
from telethon.sync import TelegramClient
from telethon import functions, types
with TelegramClient(name, api_id, api_hash) as client:
result = client(functions.account.UpdateStatusRequest(
offline=False
))
print(result)
items = node.find_elements_by_xpath('xpath')
for item in items:
print(item.get_attribute('href'))
[getattr(root, attr)(value) for attr, value in [('title', 'Title'), ('geometry', '300x250') ]]
//span[text()='Российский рубль']/preceding-sibling::span
import requests
from fake_useragent import UserAgent
from lxml import etree
url = "https://www.google.com/search?q=%D0%B4%D0%BE%D0%BB%D0%BB%D0%B0%D1%80&oq=" \
"%D0%B4%D0%BE%D0%BB%D0%BB%D0%B0%D1%80&aqs=chrome.0.69i59j0i67i131i433j0i6" \
"7i433j0i67j0i67i433j46i433i512j0i67j0i433i512l2j0i512.6063j0j1&sourceid=chrome&ie=UTF-8"
gd = UserAgent().chrome
response = requests.get(url, headers={'User-Agent': gd})
htmlparser = etree.HTMLParser()
tree = etree.fromstring(response.text, htmlparser)
result = tree.xpath("//div[contains(text(),'Российский рубль')]")
price = result[0].text.split()[0]
print(f'Стоимость доллара: {price} руб.')
Стоимость доллара: 72,75
Process finished with exit code 0