Parsing Python, how to log in?

  • 0
    Good day.
    There was a need for parsing, and I just started learning Python. The parser itself was written by the template, everything works, but you need to log in to the site and collect data, ~ 98 table pages.
    I tried requests but came across the fact that the url to which I am constantly changing, and I get the error Url is not def ...
    Tell me how in my case you can log in. Thank you all in advance!

    import requests

    def autoriz ():
    session = requests.Session ()
    url = ' '
    data = {'username': '******', 'password': '*******'}

    print (requests.get (url)). text

    def main ():
    autoriz ()

    if __name__ == '__main__':
    main ()
    Python Anonymous, Aug 3, 2019

  • 1 Answers
  • 0
    You instantiate session, but make the request outside of the session and don't use data.

    Official documentation reads:

    s = requests.Session()
    s.auth = ('user', 'pass')
    # необходимые заголовки, желательно сменить хотя бы User-agent
    # иначе цель будет видеть вас как python requests и в 99% случаев блокировать
    s.headers.update({'x-test': 'true'})

    # both 'x-test' and 'x-test2' are sent
    s.get('', headers={'x-test2': 'true'})
    Caleb Castaneda

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!