Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8968931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:31:24+00:00 2026-06-15T17:31:24+00:00

Trying to get html code of http://groupon.cl/descuentos/santiago-centro with the following python code: import urllib.request

  • 0

Trying to get html code of http://groupon.cl/descuentos/santiago-centro with the following python code:

import urllib.request
url="http://groupon.cl/descuentos/santiago-centro"
request = urllib.request.Request(url, headers = {'user-agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'})
response = urllib.request.urlopen(request)
return response.read().decode('utf-8')

I’m getting html code for a page which asks for my location. If I manually open the same link with my browser (having no cookies involved, even with a recently installed browser) I go directly to a page with discount promotions. It seems to be some redirect action that is not taken place for urllib. I am using the user-agent header to try to get the behaviour for a typical browser, but I have no luck.

How could I get the same html code as with my browser?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:31:25+00:00Added an answer on June 15, 2026 at 5:31 pm

    I think you can run this command:

    wget -d http://groupon.cl/descuentos/santiago-centro
    

    and you will see the wget print two http request and save the response page to a file.

     -   HTTP/1.1 302 Moved Temporarily
     -   HTTP/1.1 200 OK
    

    and the content of the file was html code of you want.

    The first response code is 302, so urllib.requst.urlopen do a second request. But it dit not
    set the correct cookie which get from the first response, the server cannot undstand the
    second request, so you get another page.

    The http.client module does not handle the 301 or 302 http reponse by himself.

    import http
    
    conn = http.client.HTTPConnection("groupon.cl")
    #do first request
    conn.request("GET", "/descuentos/santiago-centro")
    print(conn.status)  # 301 or 302
    print(conn.getheaders()) # set-Cookie
    
    #get the cookie
    headers = ....
    #do second request
    
    conn.requesst("GET", "/", headers)
    ......
    ......
    #Get response page.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get some HTML to work with my python code. I've got
I'm trying to get an IFrame inner HTML using below code. <iframe src=http://www.msn.com width=100%
I am trying to get form parameters from a GET request. The html code
I'm trying to get the html source for a site using the following code
Currently, I'm trying to get a list of advertisers (See http://code.google.com/apis/gan/v1beta1/advertisers/list.html ) with my
I am trying to get a working regular expression to convert standard HTML code
I'm trying to get a HTML source of a website through C# code. When
I am trying to get an HTML-based recursive directory listing based on code here:
I have the following html code: <ul class=smenu> <li class=smenuitem><a href=http://ux.stackexchange.com/></a></li> <li class=smenuitem><a href=http://area51.stackexchange.com/></a></li>
Can not seem to get this code working: http://jsfiddle.net/fxBEg/13/ What i am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.