コード例 #1
0
async def chrome_devtools_protocol_send(url, astr, params={}, id=0):
    astr = astr.strip()
    if not id: id = U.ct()
    if py.istr(astr) and not (astr.startswith('{') and astr.endswith('}')):
        astr = py.dict(
            id=id,
            method=astr,
            params=params,
        )
    if py.isdict(astr):
        astr = T.json_dumps(astr)
    return astr, await websocket_client_send(url, astr)
コード例 #2
0
ファイル: es_0731_mfyq.py プロジェクト: QGB/js
def get_recognized(a):
    st = ''
    if not py.isdict(a[5]): return py.No('a[5] is not dict', a)
    for i in a[5]:
        d = a[5][i]
        if d['success']:
            if not st:
                st = '<br>' + '=' * 110
            st += '<br><img src="{}" ><br>'.format(i)
            for line in d['result']:
                st += line['content']

    return st
コード例 #3
0
def pop_item_url_from_id_list(a):
    if not a: return ''
    id = ''
    if py.isdict(a):
        id, v = a.popitem()
    if py.islist(a):
        id = a.pop()  #-1
    if py.islist(id):
        id = id[-3]
    if not id: return ''
    if 'id=' not in id:
        return 'https://item.taobao.com/item.htm?id=' + id
    else:
        return 'https://item.taobao.com/item.htm?id=' + T.sub(id, 'id=', '')
コード例 #4
0
ファイル: taobao_trade.py プロジェクト: QGB/QPSU
async def add_cart_item(item_id, skuid, cookies=None, c3=None):
    import requests
    item_id, skuid = U.tuple_operator((item_id, skuid), operator=str)
    if not cookies:
        cookies = await taobao_trade.get_taobao_cookies()
    if not c3:
        c3 = U.get_or_dill_load(await taobao_trade.get_user() + '.c3')
    if not c3:
        need_c3  #U.set(await tb.get_user()+'.c3',_592)
    headers = {
        'authority': 'cart.taobao.com',
        'user-agent':
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
        'accept': '*/*',
        'sec-fetch-site': 'same-site',
        'sec-fetch-mode': 'no-cors',
        'sec-fetch-dest': 'script',
        'referer': 'https://item.taobao.com/item.htm?id={}'.format(item_id),
        'accept-language': 'zh-CN,zh;q=0.9',
    }

    params = [
        ('item_id', item_id),
        ('outer_id', skuid),
        ('outer_id_type', '2'),
        ('quantity', '1'),
        ('opp', ''),
        # ('nekot', '1636440805284'),
        # ('ct', '79dc2b83edef763f0981fe039467e21a'),
        # ('_tb_token_', '5011bbe7d1931'),
        ('deliveryCityCode', '430104'),
        ('frm', ''),
        ('buyer_from', ''),
        ('item_url_refer', ''),
        ('root_refer', ''),
        ('flushingPictureServiceId', ''),
        # ('spm', '2013.1.20140002.d2.undefined'),
        ('ybhpss', ''),
    ]

    if py.isdict(c3): c3 = c3.items()
    params.extend(c3)

    response = requests.get('https://cart.taobao.com/add_cart_item.htm',
                            headers=headers,
                            params=params,
                            cookies=cookies)
    # print(response,response.text[:222])
    return response
コード例 #5
0
ファイル: taobao_trade.py プロジェクト: QGB/QPSU
async def set_pages_onload(pages=None, viewport=VIEW_PORT):
    if not pages:
        p4s = await get_pages_onload()
        pages = [i[2] for i in p4s]
    for page in pages:
        try:
            if await page.evaluate(JS_DETECT_AUTOMATION):
                await page.evaluateOnNewDocument(JS_ONLOAD)
                await page.evaluate(JS_ONLOAD)
                # await page.reload() # 刷新才生效
                if viewport and py.isdict(viewport):
                    await page.setViewport(viewport)
        except Exception as e:
            print(e)
    return await get_pages_onload(pages=pages)
コード例 #6
0
ファイル: HTML.py プロジェクト: QGB/QPSU
def select(iterable, **ka):
    '''
#<!-- 
				# 不能用  editable="false" readyonly  
				#   <h6>包裹input无效 </h6>   
				# background="green" 无效 , lavender淡紫色, 熏衣草花 ,#e6e6fa 太淡啦
				#  -->	
	 '''
    response = U.get_duplicated_kargs(ka, 'p', 'resp', 'response', 'rp')
    request = U.get_duplicated_kargs(ka, 'q', 'req', 'request', 'requests',
                                     'rq')
    url = U.get_duplicated_kargs(ka, 'url', 'mark_url', 'request_url')

    if N.is_flask_request(request) and not url:
        url = request.url
    if N.is_flask_request(url):
        url = request.url
    if url:
        url = T.url_decode(url)
    else:
        url = ''

    ha = '''
<head>
	<style type="text/css">
		textarea {
			background: lightgoldenrodyellow;
			width:80%;
			
			# rows:1; # 无效

		}

	</style>
</head>	
<form action="/r=N.HTML.select_result(request,response)%23"  method="post">
	{rows}
	<input type="submit" > 
</form>

'''
    ####################
    hd = '''
<span > {i} </span>
<input type="checkbox" name="{name}" {checked} > {k} </input>
<textarea> {v} </textarea>
<hr>'''

    ########################
    def do_resp(r, kv, disabled):
        if response:
            rows = '''
<input  type="text"  readonly="readonly"  name="{G_SELECT_ID}" value={id}  style="
    # background: aqua;
    background: cyan;
" >
<input  type="text"  readonly="readonly"  name="{G_SELECT_URL}" value={url} style="
    background: lightgray;
	width:80%
"> 
<br>
			'''.format(url=url,
              id=id,
              G_SELECT_ID=G_SELECT_ID,
              G_SELECT_URL=G_SELECT_URL)
            i = 0
            # fk=lambda k: T.html_encode(repr(k))  #为啥会出现 0 ☑ q." checked > '
            fk = lambda _k: T.html_encode(repr(_k))
            fv = lambda _v: T.html_encode(repr(_v)[:155 - 1])  # 全中文 80% 正好两行
            # U.msgbox(list(kv)[:9])
            for k, v in kv:
                # k,v=fk(k),fv(v)
                # U.msgbox(k,v)
                rows += hd.format(i=i,
                                  name=r.id(k, v),
                                  k=fk(k),
                                  v=fv(v),
                                  checked='checked')
                i += 1
            for k, v in disabled:
                # k,v=fk(k),fv(v)
                rows += hd.format(i=i,
                                  name=r.id(k, v),
                                  k=fk(k),
                                  v=fv(v),
                                  checked='')
                i += 1
            # py.importU().log(rows)
            response.headers['Content-Type'] = 'text/html;charset=utf-8'
            response.set_data(T.format(ha, rows=rows))
        return r

    id = getattr(iterable, 'id', 0)
    if not id:
        id = py.id(iterable)
    if py.isdict(iterable):
        if isinstance(iterable, DictSelect):
            rd = iterable
        elif id not in gid_select:
            rd = gid_select[id] = DictSelect(iterable)
            rd.id = id
        else:
            rd = gid_select[id]
        return do_resp(rd, rd.items(), rd.disabled.items())

    if py.islist(iterable):
        if isinstance(iterable, ListSelect):
            rd = iterable
        elif id not in gid_select:
            rd = gid_select[id] = ListSelect(iterable)
            rd.id = id
        else:
            rd = gid_select[id]
        return do_resp(rd, enumerate(rd), enumerate(rd.disabled))
コード例 #7
0
ファイル: taobao_trade.py プロジェクト: QGB/QPSU
async def set_cookies(ck, page=py.No('auto last -1')):
    if not page: page = await get_page()
    if py.islist(ck):
        await page.setCookie(*ck)
    if py.isdict(ck):
        await page.setCookie(ck)
コード例 #8
0
ファイル: taobao_trade.py プロジェクト: QGB/QPSU
async def del_cookies(ck, page=py.No('auto last -1')):
    page = await get_or_new_page(page)
    if py.islist(ck):
        await page.deleteCookie(*ck)
    if py.isdict(ck):
        await page.deleteCookie(ck)