Exemplo n.º 1
0
def test_client_cookies():
    client = Client()
    client.cookies = {"a": "b"}
    assert isinstance(client.cookies, Cookies)
    mycookies = list(client.cookies.jar)
    assert len(mycookies) == 1
    assert mycookies[0].name == "a" and mycookies[0].value == "b"
Exemplo n.º 2
0
async def test_setting_client_cookies_to_cookiejar():
    """
    Send a request including a cookie, using a `CookieJar` instance.
    """

    url = "http://example.org/echo_cookies"
    cookies = CookieJar()
    cookie = Cookie(
        version=0,
        name="example-name",
        value="example-value",
        port=None,
        port_specified=False,
        domain="",
        domain_specified=False,
        domain_initial_dot=False,
        path="/",
        path_specified=True,
        secure=False,
        expires=None,
        discard=True,
        comment=None,
        comment_url=None,
        rest={"HttpOnly": None},
        rfc2109=False,
    )
    cookies.set_cookie(cookie)

    client = Client(dispatch=MockDispatch())
    client.cookies = cookies
    response = await client.get(url)

    assert response.status_code == 200
    assert response.json() == {"cookies": "example-name=example-value"}
Exemplo n.º 3
0
def find_urls(client: httpx.Client, url: str):
    if url in parsed_urls:
        return
    if 'https://l-tike' not in url:
        print('not found:', url)
        return
    if not url.startswith('http'):
        return
    print('next: ', url)
    client.cookies = None
    try:
        r = client.get(url)
    except Exception as e:
        find_urls(client, url)
        print('error:', url)
        return

    parsed_urls.add(url)
    dom = pq(r.text)

    for a in dom('main a').items():
        href = a.attr('href')
        href = urllib.parse.urljoin(bsae_url, href)
        if '/order/' in href:
            order_urls.add(href)
            print('order:', len(order_urls))
            continue

        find_urls(client, href)