R
R
r4khic2019-09-09 08:45:31
Python
r4khic, 2019-09-09 08:45:31

Request.exceptions.InvalidSchema: Connection adapters not found. How to solve?

I welcome everyone! I am parsing the date from this resource . Here is the date lbQvR.png
Here is the code

The code
# < Получаем ссылки и дату с главной страницы где берутся ссылки.
def get_resource_links(resource_page, datetimes_main_rule, links_rule, resource_domain):
    resource_links = []
    soup = BeautifulSoup(resource_page,'lxml')
    resource_links_blocks = soup.find_all(links_rule[0], {links_rule[1]: links_rule[2]})
    main_page_datetime = soup.find(datetimes_main_rule[0], {datetimes_main_rule[1]: datetimes_main_rule[2]})
    if (len(datetimes_main_rule) == 3):
        main_page_datetime = soup.find(datetimes_main_rule[0], {datetimes_main_rule[1]: datetimes_main_rule[2]})
    for resource_link_block in resource_links_blocks:
        a_tag = resource_link_block .find("a")
        if a_tag:
            link = a_tag.get("href")
            resource_links.append(resource_domain + link)
    return (resource_links, main_page_datetime)

In this piece of code I am parsing the date:
main_page_datetime = soup.find(datetimes_main_rule[0], {datetimes_main_rule[1]: datetimes_main_rule[2]})
    if (len(datetimes_main_rule) == 3):
        main_page_datetime = soup.find(datetimes_main_rule[0], {datetimes_main_rule[1]: datetimes_main_rule[2]})

When I run the code, I get this error:
traceback
Traceback (most recent call last):
  File "C:/Users/Администратор/PycharmProjects/Task/parser.py", line 142, in <module>
    call_all_func(resources)
  File "C:/Users/Администратор/PycharmProjects/Task/parser.py", line 123, in call_all_func
    item_page = get_html(resource_link, encodings_rule)
  File "C:/Users/Администратор/PycharmProjects/Task/parser.py", line 17, in get_html
    r = requests.get(url)
  File "C:\Users\Администратор\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\Администратор\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\Администратор\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\Администратор\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 640, in send
    adapter = self.get_adapter(url=request.url)
  File "C:\Users\Администратор\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 731, in get_adapter
    raise InvalidSchema("No connection adapters were found for '%s'" % url)
requests.exceptions.InvalidSchema: No connection adapters were found for '['https://kapital.kz/finance/81046/nacvalyuta-k-dollaru-ukrepilas-na-1-2-tenge.html', 'https://kapital.kz/real_estate/81045/baspana-hit-kazahstancy-kupili-svyshe-13-tysyach-kvartir.html', 'https://kapital.kz/finance/81044/obem-potrebitelskih-kreditov-dostig-3-8-trln-tenge.html', 'https://kapital.kz/economic/80977/ayan-erenov-eksportnaya-orientirovannost-v-strany-ca-daet-rezultaty.html', 'https://kapital.kz/business/80961/kak-razvivaet-biznes-edinstvennyj-proizvoditel-bytovoj-himii-zko.html', 'https://kapital.kz/gosudarstvo/80974/ao-i-too-osobennosti-deyatelnosti-i-regulirovaniya.html', 'https://kapital.kz/business/80954/kazahstanec-vyvel-na-rynok-innovacionnyj-gel.html', 'https://kapital.kz/gosudarstvo/81043/sotrudnichestvo-s-oae-i-rossiej-rejting-kazahstana-podderzhka-proizvoditelej.html', 'https://kapital.kz/tehnology/81042/v-moody-s-predskazali-standartizaciyu-tehnologii-blokchejn.html', 'https://kapital.kz/world/81041/torgovlya-kitaya-i-ssha-sokratilas-na-14.html', 'https://kapital.kz/economic/81040/kak-otlichayutsya-ceny-na-bilety-v-kino-v-kazahstane-i-mire.html', 'https://kapital.kz/world/81039/palata-lordov-utverdila-proekt-o-perenose-brexit.html', 'https://kapital.kz/finance/81038/mfo-operezhayut-banki-po-tempam-rosta-kreditovaniya.html', 'https://kapital.kz/world/81037/telegram-razreshil-polzovatelyam-skryvat-nomer-telefona.html', 'https://kapital.kz/gosudarstvo/81036/chto-bolshe-vsego-chitali-na-etoj-nedele-na-kapital-kz.html']'

Process finished with exit code 1

Based on the traceback , the error lies in this section of code:
The code
def get_html(url, encodings_rule):
    try:
        r = requests.get(url)
        if (len(encodings_rule) == 1):
            r.encoding = encodings_rule[0]
            return r.text
    except TooManyRedirects as e:
        print(f'{url} : {e}')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Noskov, 2019-09-11
@DENZEL_WASHINGTON

in the URL not str but list turned out to be
https://2.python-requests.org/en/master/_modules/r...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question