How to identify the original HTTP request from client? - python

"To display a Web page, the browser sends an original request to fetch
the HTML document that represents the page. It then parses this file,
making additional requests corresponding to execution scripts, layout
information (CSS) to display, and sub-resources contained within the
page (usually images and videos)."
The previous quote is form MDN Web Docs An overview of HTTP
My question is: I want to identify the original request from the client, and then temporarily store the request and all subrequests made to the server, but when the client make another original request I want to replace the temporarily data with the new requests.
for example let say that I have an html page that when parsed by the client make additional requests to some resources on the server, when the user reload the page he is just making another original request, so the temporarily stored request data should be replaced by the new original request and its subrequests, the same happens when the client request for another html page.

Related

Django URL does not see the link and its POST request

I made a project, but in it you need to get a special token from the VK social network. I made the token pass along with the link. She looks like this:
http://127.0.0.1:8000/vk/auth#access_token=7138dcd74f5da5e557943b955bbfbd9a62811da7874067e5fa0edef1ca8680216755be16&expires_in=86400&user_id=397697636
But the problem is that the django cannot see this link. I tried to look at it in a post request, get request, but everything is empty there. I tried to make it come not as a request but as a link, it is like this:
http://127.0.0.1:8000/vk/auth #access_token=7138dcd74f5da5e557943b955bbfbd9a62811da7874067e5fa0edef1ca8680216755be16&expires_in=86400&user_id=397697636
But the django does not want to read the space. Who can help
I think there is a confusion between a query string (get params) that follows a ? and a fragment (the text, that follows a #)
What follows the # is not sent to the server (and thus not received by Django) it is only useful to the web browser and to the javascript that is executed on the browser , which can use it to update parts of the screen. use it as virtual urls / bookmarks for one page web applications.
The javascript can of course also trigger AJAX requests using that data, but that's up to the javascript
If you write however http://127.0.0.1:8000/vk/auth?access_token=7138dcd74f5da5e557943b955bbfbd9a62811da7874067e5fa0edef1ca8680216755be16&expires_in=86400&user_id=397697636 (you replace # with ?)
Then you can receive the information in your django view with
request.GET["access_token"], request.GET["expires_in"] and request.GET["user_id"]
If it is really a #, then your javascript should parse whatever follows the # and make the according AJAX requests to the server to send / validate the token.
For another question about fragments, refer for example to Is the URL fragment identifier sent to the server?

Page content not in response to get request

I'm trying to access my transaction history from my online banking page using python and requests. I have no trouble logging on with requests and getting my account overview page content but the bank account transaction data is not in the response text. Obviously, it shows up in my browser when I access the same page.
Viewing the raw html through my browser, my bank transaction data is present; however, it is not present in the response content I receive from a get request in python.
I'm thinking this has something to do with the following:
When the page is accessed through a browser, the transaction data is temporarily not visible because it is being loaded by some unknown background process. I think that the same process is happening when I access the site via python but the request response only contains the content that is present during the initial state of page when accessed; this state does not include the transaction data because the data is still loading.
One thing that supports this theory is the fact that the response text received through python and the response text in the browser (when viewed in developer tools) are identical until this line in the html:
<div id="accountRefreshDiv" style="display:none"><img blah blah>Updating...</div>
"Updating" also appears in the browser, along with a little spiny wheel, when the page is first accessed.
So my question is, what type of sub process could be going on in the background and how do I go about fetching the data that it is fetching (probably with JavaScript) but with python?

Pass Data From Python To Html <p> Tag

I am developing a project on Python using Django. The project is doing lot of work in the background so i want to notify users what's going on now in the system. For this i have declared a p tag in HTML and i want to send data to it.
I know i can do this by templates but i am little confused as 5 functions need to pass the status to the p tag and if i use render_to_response() it refreshes the page every time a status is passed from the function
Anyone please tell me how to do this in the correct way
Part of your page that contains the paragraph tags is a piece of JavaScript that contains a timer.
Every once in a while it does an Ajax request to get the data with regard to "what's going on now in the system".
If you use the Ajax facilites of JQuery, which is probably the easiest, you can pass a JavaScript callback function that will be called if the request is answered. This callback function receives the data served by Django as response to the asynchroneous request. In the body of this callback you put the code to fill your paragraph.
Django doesn't have to "know" about Ajax, it just serves the required info from a different URL than your original page containing the paragraph tags. That URL is part the your Ajax request from the client.
So it's the client that takes the initiative. Ain't no such thing as server push (fortunately).

Parse HTML Infinite Scroll

I'm trying to parse the HTML of a page with infinite scrolling. I want to load all of the content so that I can parse it all. I'm using Python. Any hints?
Those pages update their html with AJAX. Usually you just need to find the new AJAX requests send by browser, guess the meaning of the AJAX url parameters and fetch the data from the API.
API servers may validate the user agent, referer, cookie, oauth_token ... of the AJAX request, keep an eye on them.
the data is
either loaded in advance
or the page sends a request while you scroll
you can use httpfox to find the request and send it

going to next page using django paginator sends request again.

My google search application making a request each time while i am using paginator. Suppose i have a 100 records. Each page have to show 10 records so ten pages. When i click 2nd page it again sending a request. Ideally it should not send the request.
When i click 2nd page it again sending a request. Ideally it should not send the request.
What do you mean by request? Is it a request to Google?
Your application apparently does not cache the results. If your request to Google returns 100 pages then you should cache those hundred. When you request the second page the view should retrieve this cache and return the second page to you.
If you mean request to your app, then #Daniel's comment has it right. You can get around this by sending all the results to the browser and then do the pagination using JavaScript to avoid this.
A more detailed answer is difficult without seeing some code.

Categories

Resources