Search code examples
web-scrapinghttp-headershttpwebrequest

Observe http request and simulate the same request in code


Is there a way to observe a http request in the browser and save that request (header data and parameters) and simulate the same request in code?

What I want is to "simulate" a browser in my project, to get the same response back like if the user is using a normal browser.

I don't know exactly how to ask the question correctly, but what I want is to simulate the authentification on some websites and scrape the same data as when I were in the browser.


Solution

  • What I wanted was to crawle a website, which is secured with authentification, using simple http-requests and build the request-header in my code. And it was not only about sending a POST-request with name + password, but also some other hidden parameters which are first generated when a user visits the website - on the clientside with javascript. Maybe it is possible to understand the algorithm behind generating those hidden parameters, but it can take a long time because of the complexity.

    The best way to crawle a website in a automated way without caring about the correct headers is to use a "headless" browser, which is nothing else then a normal browser without a GUI. You can control it in your code. A list of those headless browsers can be found here.

    So no need for observing and recording the request and simulating it in code - just use a headless browser.