0

Я новичок , не могу понять как сделать авторизацию, точнее куда ее залепить,прочитал как, но на практике не получается

import time
import requests
import lxml.html

class MyParser:
    def __init__(self, base_url):
        self.base_url = base_url
        self.last_time = ''

    def get_page(self):
        try:
            res = requests.get(self.base_url)
        except requests.ConnectionEror:
            return

        if res.status_code < 400:
            return res.content

    def parse(self, html):
        html_tree = lxml.html.fromstring(html)
        offers = html_tree.xpath(".//tbody/tr")
        print(offers)

    def run(self):
        pass
if __name__ == "__main__":

    parser = MyParser('http.......')
    page = parser.get_page()

    parser.parse(page)

1 ответ 1

0
import requests
from lxml import etree, html
import codecs


auth_url = 'https://auth.site.com/cgi-bin/auth'
auth_field_login = 'Login'
auth_field_passw = 'Password'
auth_value_login = '********@site.com'
auth_value_passw = '********'
target_url = 'https://myprofile.site.com/'

session = requests.Session()
params = {auth_field_login: auth_value_login, auth_field_passw: auth_value_passw}
s = session.post(auth_url, params)
s = session.get(target_url)
document_root = html.fromstring(s.text)
with codecs.open('output.txt', 'w', 'utf-8') as f:
    f.write(etree.tostring(document_root, encoding='unicode', pretty_print=True).replace('\n', '\r\n'))

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.