首页 > 解决方案 > Scraping an ASPX page with authentication. Using Python 3

问题描述

I am trying to use python`s requests library to scrape an ASPX site and get information from a Table inside.

The problem I am experiencing has also been well described in How to web scrape an ASPX page that requires authentication with no replies at the time of writing.

The way I am currently going about it is by:

Further to this, the login_data dictionary is being passed to a post request to the login_url as the data.

The same session is then used to try and get the request from the report_url.

response_1 = session.post(login_url, data=login_data)
response_2 = session.get(report_url)

The problem seems to be that the login is not being effected. as the get request is being re-routed to a login page.

Can anyone kindly shed some light on why this is the case? I am guessing that this is the correct flow, however please let me know if there is anything I am doing wrong or that can be improved.

I am unfortunately currently limited to using only requests or other popular python 3 libraries as it is a requirement (using references to "browser".exe files, as suggested in some replies on the subject, is not an option.)

标签: asp.netpython-3.xweb-scrapingbeautifulsouppython-requests

解决方案


推荐阅读