open a webpage with the same data as the response of a python requests script











up vote
0
down vote

favorite
1












import requests

session = requests.Session()
session.headers.update({'Some headers'})
session.headers.update({'Some headers'})
session.headers.update({'Some headers'})
session.headers.update({'Some headers'})
session.headers.update({'Some headers'})

session.get('SomeWebsite').url


From this script I get an URL.



Just typing in the url wont work, because It doesnt have the same headers as In the response.



For Example If I go to www.example.com with the standard CF-RAY, I'll be redirected to A website www.example.com/No



If I go to www.example.com with the CF-RAY that I got from the response I'll be redirected to www.example.com/Yes



Bassicly In looking for something like this



session.get('SomeWebsite').OpenUrlInMyBrowser


Thanks alot!
Stefan










share|improve this question
























  • Can you explain clearly what you want? Did you desire to get same response as browser? If true you need to post your example url, cause dynamic loading
    – kcorlidy
    Nov 8 at 3:03










  • @kcorlidy If I execute the scipt given, than I get an html code of the response. I bet there's a url option, but then I wont go to the website with the same response headers
    – S. Known
    Nov 8 at 7:48












  • You mean session.get('SomeWebsite').cookies ? They have difference between response header and request header. Or you mean random header?
    – kcorlidy
    Nov 8 at 8:36










  • @kcorlidy It isnt just the cookies
    – S. Known
    Nov 8 at 9:27










  • @kcorlidy I updated the quistion, Did it help
    – S. Known
    Nov 8 at 9:33















up vote
0
down vote

favorite
1












import requests

session = requests.Session()
session.headers.update({'Some headers'})
session.headers.update({'Some headers'})
session.headers.update({'Some headers'})
session.headers.update({'Some headers'})
session.headers.update({'Some headers'})

session.get('SomeWebsite').url


From this script I get an URL.



Just typing in the url wont work, because It doesnt have the same headers as In the response.



For Example If I go to www.example.com with the standard CF-RAY, I'll be redirected to A website www.example.com/No



If I go to www.example.com with the CF-RAY that I got from the response I'll be redirected to www.example.com/Yes



Bassicly In looking for something like this



session.get('SomeWebsite').OpenUrlInMyBrowser


Thanks alot!
Stefan










share|improve this question
























  • Can you explain clearly what you want? Did you desire to get same response as browser? If true you need to post your example url, cause dynamic loading
    – kcorlidy
    Nov 8 at 3:03










  • @kcorlidy If I execute the scipt given, than I get an html code of the response. I bet there's a url option, but then I wont go to the website with the same response headers
    – S. Known
    Nov 8 at 7:48












  • You mean session.get('SomeWebsite').cookies ? They have difference between response header and request header. Or you mean random header?
    – kcorlidy
    Nov 8 at 8:36










  • @kcorlidy It isnt just the cookies
    – S. Known
    Nov 8 at 9:27










  • @kcorlidy I updated the quistion, Did it help
    – S. Known
    Nov 8 at 9:33













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





import requests

session = requests.Session()
session.headers.update({'Some headers'})
session.headers.update({'Some headers'})
session.headers.update({'Some headers'})
session.headers.update({'Some headers'})
session.headers.update({'Some headers'})

session.get('SomeWebsite').url


From this script I get an URL.



Just typing in the url wont work, because It doesnt have the same headers as In the response.



For Example If I go to www.example.com with the standard CF-RAY, I'll be redirected to A website www.example.com/No



If I go to www.example.com with the CF-RAY that I got from the response I'll be redirected to www.example.com/Yes



Bassicly In looking for something like this



session.get('SomeWebsite').OpenUrlInMyBrowser


Thanks alot!
Stefan










share|improve this question















import requests

session = requests.Session()
session.headers.update({'Some headers'})
session.headers.update({'Some headers'})
session.headers.update({'Some headers'})
session.headers.update({'Some headers'})
session.headers.update({'Some headers'})

session.get('SomeWebsite').url


From this script I get an URL.



Just typing in the url wont work, because It doesnt have the same headers as In the response.



For Example If I go to www.example.com with the standard CF-RAY, I'll be redirected to A website www.example.com/No



If I go to www.example.com with the CF-RAY that I got from the response I'll be redirected to www.example.com/Yes



Bassicly In looking for something like this



session.get('SomeWebsite').OpenUrlInMyBrowser


Thanks alot!
Stefan







python python-2.7 python-requests






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 9:37

























asked Nov 7 at 11:30









S. Known

25




25












  • Can you explain clearly what you want? Did you desire to get same response as browser? If true you need to post your example url, cause dynamic loading
    – kcorlidy
    Nov 8 at 3:03










  • @kcorlidy If I execute the scipt given, than I get an html code of the response. I bet there's a url option, but then I wont go to the website with the same response headers
    – S. Known
    Nov 8 at 7:48












  • You mean session.get('SomeWebsite').cookies ? They have difference between response header and request header. Or you mean random header?
    – kcorlidy
    Nov 8 at 8:36










  • @kcorlidy It isnt just the cookies
    – S. Known
    Nov 8 at 9:27










  • @kcorlidy I updated the quistion, Did it help
    – S. Known
    Nov 8 at 9:33


















  • Can you explain clearly what you want? Did you desire to get same response as browser? If true you need to post your example url, cause dynamic loading
    – kcorlidy
    Nov 8 at 3:03










  • @kcorlidy If I execute the scipt given, than I get an html code of the response. I bet there's a url option, but then I wont go to the website with the same response headers
    – S. Known
    Nov 8 at 7:48












  • You mean session.get('SomeWebsite').cookies ? They have difference between response header and request header. Or you mean random header?
    – kcorlidy
    Nov 8 at 8:36










  • @kcorlidy It isnt just the cookies
    – S. Known
    Nov 8 at 9:27










  • @kcorlidy I updated the quistion, Did it help
    – S. Known
    Nov 8 at 9:33
















Can you explain clearly what you want? Did you desire to get same response as browser? If true you need to post your example url, cause dynamic loading
– kcorlidy
Nov 8 at 3:03




Can you explain clearly what you want? Did you desire to get same response as browser? If true you need to post your example url, cause dynamic loading
– kcorlidy
Nov 8 at 3:03












@kcorlidy If I execute the scipt given, than I get an html code of the response. I bet there's a url option, but then I wont go to the website with the same response headers
– S. Known
Nov 8 at 7:48






@kcorlidy If I execute the scipt given, than I get an html code of the response. I bet there's a url option, but then I wont go to the website with the same response headers
– S. Known
Nov 8 at 7:48














You mean session.get('SomeWebsite').cookies ? They have difference between response header and request header. Or you mean random header?
– kcorlidy
Nov 8 at 8:36




You mean session.get('SomeWebsite').cookies ? They have difference between response header and request header. Or you mean random header?
– kcorlidy
Nov 8 at 8:36












@kcorlidy It isnt just the cookies
– S. Known
Nov 8 at 9:27




@kcorlidy It isnt just the cookies
– S. Known
Nov 8 at 9:27












@kcorlidy I updated the quistion, Did it help
– S. Known
Nov 8 at 9:33




@kcorlidy I updated the quistion, Did it help
– S. Known
Nov 8 at 9:33












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Not sure if this helps, I still don't completely understand your question.



You can display the headers of the response you get using:



session.get('SomeWebsite').headers



and include those in a new request. You could do this with a blanket:



response = session.get("http://www.example.com")
session2 = requests.Session()
session2.headers.update(response.headers)


but this doesn't make much sense because the defined headers for requests and responses are not the same. So you have to manually select the properties you want.



If you are not sure which properties you need this will tell you how to show all the info from a request.



This is how you open a URL in your browser



import webbrowser
webbrowser.open_new("http://www.example.com")





share|improve this answer























  • Did you ever see you request header with this code? Mr. You are doing something terrible
    – kcorlidy
    Nov 8 at 10:00










  • @kcorlidy What is your question?
    – Pumpkin
    Nov 8 at 10:02










  • I think you should try your code and see your request content, which contains lots of it should not have, like Status
    – kcorlidy
    Nov 8 at 10:04










  • @kcorlidy I just want to open the response in my browser
    – S. Known
    Nov 8 at 10:56










  • @S.Known I added how to open a URL in your browser. Is that what you are looking for? It does, however, not allow you to edit the header.
    – Pumpkin
    Nov 8 at 11:45











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53188618%2fopen-a-webpage-with-the-same-data-as-the-response-of-a-python-requests-script%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Not sure if this helps, I still don't completely understand your question.



You can display the headers of the response you get using:



session.get('SomeWebsite').headers



and include those in a new request. You could do this with a blanket:



response = session.get("http://www.example.com")
session2 = requests.Session()
session2.headers.update(response.headers)


but this doesn't make much sense because the defined headers for requests and responses are not the same. So you have to manually select the properties you want.



If you are not sure which properties you need this will tell you how to show all the info from a request.



This is how you open a URL in your browser



import webbrowser
webbrowser.open_new("http://www.example.com")





share|improve this answer























  • Did you ever see you request header with this code? Mr. You are doing something terrible
    – kcorlidy
    Nov 8 at 10:00










  • @kcorlidy What is your question?
    – Pumpkin
    Nov 8 at 10:02










  • I think you should try your code and see your request content, which contains lots of it should not have, like Status
    – kcorlidy
    Nov 8 at 10:04










  • @kcorlidy I just want to open the response in my browser
    – S. Known
    Nov 8 at 10:56










  • @S.Known I added how to open a URL in your browser. Is that what you are looking for? It does, however, not allow you to edit the header.
    – Pumpkin
    Nov 8 at 11:45















up vote
0
down vote













Not sure if this helps, I still don't completely understand your question.



You can display the headers of the response you get using:



session.get('SomeWebsite').headers



and include those in a new request. You could do this with a blanket:



response = session.get("http://www.example.com")
session2 = requests.Session()
session2.headers.update(response.headers)


but this doesn't make much sense because the defined headers for requests and responses are not the same. So you have to manually select the properties you want.



If you are not sure which properties you need this will tell you how to show all the info from a request.



This is how you open a URL in your browser



import webbrowser
webbrowser.open_new("http://www.example.com")





share|improve this answer























  • Did you ever see you request header with this code? Mr. You are doing something terrible
    – kcorlidy
    Nov 8 at 10:00










  • @kcorlidy What is your question?
    – Pumpkin
    Nov 8 at 10:02










  • I think you should try your code and see your request content, which contains lots of it should not have, like Status
    – kcorlidy
    Nov 8 at 10:04










  • @kcorlidy I just want to open the response in my browser
    – S. Known
    Nov 8 at 10:56










  • @S.Known I added how to open a URL in your browser. Is that what you are looking for? It does, however, not allow you to edit the header.
    – Pumpkin
    Nov 8 at 11:45













up vote
0
down vote










up vote
0
down vote









Not sure if this helps, I still don't completely understand your question.



You can display the headers of the response you get using:



session.get('SomeWebsite').headers



and include those in a new request. You could do this with a blanket:



response = session.get("http://www.example.com")
session2 = requests.Session()
session2.headers.update(response.headers)


but this doesn't make much sense because the defined headers for requests and responses are not the same. So you have to manually select the properties you want.



If you are not sure which properties you need this will tell you how to show all the info from a request.



This is how you open a URL in your browser



import webbrowser
webbrowser.open_new("http://www.example.com")





share|improve this answer














Not sure if this helps, I still don't completely understand your question.



You can display the headers of the response you get using:



session.get('SomeWebsite').headers



and include those in a new request. You could do this with a blanket:



response = session.get("http://www.example.com")
session2 = requests.Session()
session2.headers.update(response.headers)


but this doesn't make much sense because the defined headers for requests and responses are not the same. So you have to manually select the properties you want.



If you are not sure which properties you need this will tell you how to show all the info from a request.



This is how you open a URL in your browser



import webbrowser
webbrowser.open_new("http://www.example.com")






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 8 at 11:44

























answered Nov 8 at 9:52









Pumpkin

537




537












  • Did you ever see you request header with this code? Mr. You are doing something terrible
    – kcorlidy
    Nov 8 at 10:00










  • @kcorlidy What is your question?
    – Pumpkin
    Nov 8 at 10:02










  • I think you should try your code and see your request content, which contains lots of it should not have, like Status
    – kcorlidy
    Nov 8 at 10:04










  • @kcorlidy I just want to open the response in my browser
    – S. Known
    Nov 8 at 10:56










  • @S.Known I added how to open a URL in your browser. Is that what you are looking for? It does, however, not allow you to edit the header.
    – Pumpkin
    Nov 8 at 11:45


















  • Did you ever see you request header with this code? Mr. You are doing something terrible
    – kcorlidy
    Nov 8 at 10:00










  • @kcorlidy What is your question?
    – Pumpkin
    Nov 8 at 10:02










  • I think you should try your code and see your request content, which contains lots of it should not have, like Status
    – kcorlidy
    Nov 8 at 10:04










  • @kcorlidy I just want to open the response in my browser
    – S. Known
    Nov 8 at 10:56










  • @S.Known I added how to open a URL in your browser. Is that what you are looking for? It does, however, not allow you to edit the header.
    – Pumpkin
    Nov 8 at 11:45
















Did you ever see you request header with this code? Mr. You are doing something terrible
– kcorlidy
Nov 8 at 10:00




Did you ever see you request header with this code? Mr. You are doing something terrible
– kcorlidy
Nov 8 at 10:00












@kcorlidy What is your question?
– Pumpkin
Nov 8 at 10:02




@kcorlidy What is your question?
– Pumpkin
Nov 8 at 10:02












I think you should try your code and see your request content, which contains lots of it should not have, like Status
– kcorlidy
Nov 8 at 10:04




I think you should try your code and see your request content, which contains lots of it should not have, like Status
– kcorlidy
Nov 8 at 10:04












@kcorlidy I just want to open the response in my browser
– S. Known
Nov 8 at 10:56




@kcorlidy I just want to open the response in my browser
– S. Known
Nov 8 at 10:56












@S.Known I added how to open a URL in your browser. Is that what you are looking for? It does, however, not allow you to edit the header.
– Pumpkin
Nov 8 at 11:45




@S.Known I added how to open a URL in your browser. Is that what you are looking for? It does, however, not allow you to edit the header.
– Pumpkin
Nov 8 at 11:45


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53188618%2fopen-a-webpage-with-the-same-data-as-the-response-of-a-python-requests-script%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings