Python请求的基本身份验证

时间:2018-05-05 20:55:30

标签: python-3.x authentication python-requests

我遇到一些问题,了解如何使用Requests lib登录网站。 所以,网站是https://lolzteam.net/ 登录名为https://lolzteam.net/login

我的简单代码:

import requests
from bs4 import BeautifulSoup, NavigableString, Tag

header = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
    'Connection': 'keep-alive',
    'X-Requested-With': 'XMLHttpRequest'
}

payload = {
    'login': 'Some name',
    'password': 'Some pass'
}

blacklist_lolz = 'https://lolzteam.net/forums/774/'
main_lolz = 'https://lolzteam.net/'

def beautifulsoup(url_content):
    return BeautifulSoup(url_content, 'lxml')


with requests.Session() as s:
    p = s.post('https://lolzteam.net/login', data=payload)
    print(p.text)

    req = s.get(blacklist_lolz)
    print(req.text)

    soup = beautifulsoup(req.content)

    divs_all = soup.find_all('a', class_='PreviewTooltip ')

    links_all = [div['href'] for div in divs_all]

for link in links_all:
    number_list = []
    link_page = requests.get(main_lolz + link, headers=header)
    link_soup = beautifulsoup(link_page.content)
   # Some code ...

现在,我不知道,有什么不对。请帮帮我:C

在循环中,我查看每个链接,在一些我看到的内容中:"您无法查看文本,您未获得授权"

0 个答案:

没有答案