F
F
Fridary2017-10-04 13:20:26
Parsing
Fridary, 2017-10-04 13:20:26

How to authorize on the site through a script?

Good afternoon everyone,
Let's say there is a news site with the ability to register users.
If the user is registered, then one content is displayed to him; if not, then another
How do I tell the script I'm developing (now in Python and PHP) that here is the username and password for this news site, upload the html data for the registered user to me?
I understand that when authorizing on the site there are cookies and sessions for verification. Let's say I can change the headers by copying them from the Chrome Debugger, but will these headers change? And will it even work?
An example of issuing Request Headers for one site is below when accessing the page via GET. It turns out that if the cookies run out, then every time I will need to go to the site manually, copy the new value and paste it into the script?

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/;q=0.8
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,ru;q=0.6
Cache-Control:no-cache
Connection:keep-alive
Cookie:PHPSESSID=sgjjv462jhc8o7jbqna6u7u1vs7; example-mo_ename=cad7d6de252ee31018d968134dcd2518f78ff; example-mo_type_auth=employer
Host:www.example.com
Pragma:no-cache
Referer:http://www.example.com/search.php?r=res&srcity=&srcategory=&submit=1
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36

Request Cookies:
PHPSESSID	sgjjv46jhc8do7jbqn6u7u1vs7	N/A	N/A	N/A	38			
example-mo_ename	cad7d6de25ee31034718df96813dcd2518f78ff	N/A	N/A	N/A	53			
example-mo_type_auth	employer

Response -- html page

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Lander, 2017-10-04
@usdglander

cURL
Options: CURLOPT_COOKIE and CURLOPT_COOKIEFILE are what you are interested in

Q
qlkvg, 2017-10-04
@qlkvg

Cookies are the least of the problems. Any sane library for working with http can keep them during the session, save them at the end and load them later. The fun starts with all sorts of xsrf and other protections. Try it, there are a ton of materials on the Internet. For an example on python+requests - https://www.youtube.com/watch?v=eRSJSKG4mDA.

X
x67, 2017-10-04
@x67

Open the debugger and authenticate. Look at the request that sends data to the site. Surely he sends a login, password + something of his own. Moreover, sometimes sites can send dynamic parameters in order to protect against automatic authorization, but this is hardly your case. Also, not the password, but its hash can be sent. You analyze the request and clone it - you will need to simulate it every time you need authorization. From the libraries, even the default requests from python will do. And no seleniums are needed, you are not going to arrange shelling of a sparrow's nest.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question