import pyautogui
im1 = pyautogui.screenshot("screen.png", region=(0, 0, 300, 400))
im1.save()
["created_at", "2022-08-11T14:01:46.886Z", "city","Lawton","country","US",]
def convert(data):
it = iter(data)
res_dct = dict(zip(it, it))
return res_dct
print(convert(data["city"],data["country"]))
async def command(client, data, status=None):
await client.send(json.dumps(data))
while True:
try:
receive = await client.recv()
code = json.loads(receive)["status"][0]
if code == status:
return receive
except (KeyError, ValueError) as err:
print(f"[error from command()] => {err}")
finally:
print(f"[websocket message] =>", receive)
await client.send(json.dumps(data))
вынести из While def e_way():
"""Get data"""
import httpx
uri = "https://eway.elevel.ru/api/goods_new/?category_id=0&own=6101"
client = httpx.Client()
r = client.post(
url=uri,
headers={
"Host": "eway.elevel.ru",
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0",
"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Content-Type": "pplication/x-www-form-urlencoded; charset=UTF-8",
"X-Request-ID": "c6bd4e99f21eea69cb291511473bf936",
"X-Requested-With": "XMLHttpRequest",
"Origin": "https://eway.elevel.ru",
"Connection": "keep-alive",
"Referer": "https://eway.elevel.ru/goods/0/",
"Cookie": "basket=7023202; contract=6101; user_uuid=687b14a6-e6aa-4661-824f-1c058c149b2e; _ym_uid=1654725714994683832; _ym_d=1654725714; _ym_isad=1",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-User": "?1",
},
# add necessary params if need
params={
"draw": "1",
"columns[0][data]": "0",
"columns[0][name]": "articul",
"columns[0][searchable]": "true",
"columns[0][orderable]": "true",
"columns[0][search][value]": "",
"columns[0][search][regex]": "false",
"columns[1][data]": "1",
"columns[1][name]": "photo",
"columns[1][searchable]": "true",
"columns[1][orderable]": "false",
"columns[1][search][value]": "",
"columns[1][search][regex]": "false",
"columns[2][data]": "2",
"columns[2][name]": "certificate",
"columns[2][searchable]": "true",
"columns[2][orderable]": "false",
"columns[2][search][value]": "",
"columns[2][search][regex]": "false",
"columns[3][data]": "3",
"columns[3][name]": "configurator",
"columns[3][searchable]": "true",
"columns[3][orderable]": "false",
"columns[3][search][value]": "",
"columns[3][search][regex]": "false",
"columns[4][data]": "4",
"columns[4][name]": "name",
"columns[4][searchable]": "true",
"columns[4][orderable]": "true",
"columns[4][search][value]": "",
"columns[4][search][regex]": "false",
"columns[5][data]": "5",
"columns[5][name]": "category",
"columns[5][searchable]": "true",
"columns[5][orderable]": "false",
"columns[5][search][value]": "",
"columns[5][search][regex]": "false",
"columns[6][data]": "6",
"columns[6][name]": "type",
"columns[6][searchable]": "true",
"columns[6][orderable]": "true",
"columns[6][search][value]": "",
"columns[6][search][regex]": "false",
"columns[7][data]": "7",
"columns[7][name]": "producer",
"columns[7][searchable]": "true",
"columns[7][orderable]": "true",
"columns[7][search][value]": "",
"columns[7][search][regex]": "false",
"columns[8][data]": "8",
"columns[8][name]": "storage",
"columns[8][searchable]": "true",
"columns[8][orderable]": "true",
"columns[8][search][value]": "",
"columns[8][search][regex]": "false",
"columns[9][data]": "9",
"columns[9][name]": "pack",
"columns[9][searchable]": "true",
"columns[9][orderable]": "true",
"columns[9][search][value]": "",
"columns[9][search][regex]": "false",
"columns[10][data]": "10",
"columns[10][name]": "step",
"columns[10][searchable]": "true",
"columns[10][orderable]": "true",
"columns[10][search][value]": "",
"columns[10][search][regex]": "false",
"columns[11][data]": "11",
"columns[11][name]": "price",
"columns[11][searchable]": "true",
"columns[11][orderable]": "true",
"columns[11][search][value]": "",
"columns[11][search][regex]": "false",
"columns[12][data]": "12",
"columns[12][name]": "tariff_price",
"columns[12][searchable]": "true",
"columns[12][orderable]": "true",
"columns[12][search][value]": "",
"columns[12][search][regex]": "false",
"columns[13][data]": "13",
"columns[13][name]": "special_offers",
"columns[13][searchable]": "true",
"columns[13][orderable]": "true",
"columns[13][search][value]": "",
"columns[13][search][regex]": "false",
"columns[14][data]": "14",
"columns[14][name]": "cart",
"columns[14][searchable]": "true",
"columns[14][orderable]": "true",
"columns[14][search][value]": "",
"columns[14][search][regex]": "false",
"order[0][column]": "14",
"order[0][dir]": "desc",
"start": "100",
"length": "100",
"search[value]": "",
"search[regex]": "false",
"sentens": "",
},
)
print("[*Response ]\n", r.json())
if __name__ == "__main__":
e_way()
def face_token():
"""Get TOKEN"""
from bs4 import BeautifulSoup
import httpx
import ssl
uri = "https://www.facebook.com/adsmanager/manage"
ctx = ssl.create_default_context()
client = httpx.Client(verify=ctx)
r = client.get(
url=uri,
headers={
"Host": "www.facebook.com",
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Referer": "https://www.facebook.com/index.php?next=https%3A%2F%2Fwww.facebook.com%2Fadsmanager%2Fmanage",
"Connection": "keep-alive",
"Cookie": "cookies_there", # use the cookies that you receive after logging into your account
"Upgrade-Insecure-Requests": "1",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-User": "?1",
"TE": "trailers",
},
)
print("[* Response headers]\n", r.headers)
# From headers you can get => privacy_mutation_token(see x-fb-debug) =
# "eyJ0eXBlIjowLCJjcmVhdGlvbl90aW1lIjoxNjU0NzE4MTg0LCJjYWxsc2l0ZV9pZCI6MzgxMjI5MDc5NTc1OTQ2fQ=="
# use it for POST https://www.facebook.com/login/?privacy_mutation_token=
# eyJ0eXBlIjowLCJjcmVhdGlvbl90aW1lIjoxNjU0NzE4MTg0LCJjYWxsc2l0ZV9pZCI6MzgxMjI5MDc5NTc1OTQ2fQ==
body = BeautifulSoup(r.text, "lxml")
print("[* All JS scripts]")
# find all scripts one of them will be "accessToken"
for script in body.find_all("script"):
print(script)
if __name__ == "__main__":
face_token()
x = []
for i in range(len(n)):
if type(n[i]) is list:
x.append(n[i])
mark = len(x) - 1
elif type(n[i]) is int:
x[mark].append(n[i])
def user(**kwargs):
return [kwargs]
if __name__ == "__main__":
data = user(n1="Text1", n2="Text2", n3="Text3")
print(data)