2

For example, I tried getting Python to read the following filtered page

http://www.hearthpwn.com/cards?filter-attack-val=1&filter-attack-op=1&display=1

but Python only gets the unfiltered page http://www.hearthpwn.com/cards instead.

geft
  • 615
  • 1
  • 6
  • 18
  • 5
    What library are you using for this? `requests`? You should update your post to include a minimal working example of your code to show what you have been doing. – Anthon Aug 20 '16 at 05:24
  • 2
    Possible duplicate of [Is there an easy way to request a URL in python and NOT follow redirects?](http://stackoverflow.com/questions/110498/is-there-an-easy-way-to-request-a-url-in-python-and-not-follow-redirects) – zachyee Aug 20 '16 at 06:27
  • @Anthon I use the standard urllib2 way of fetching urls. I'll update the post later when i have access to my pc. I should note that it used to work before, but now it doesn't. – geft Aug 20 '16 at 06:31

1 Answers1

2

The standard library urllib2 normally follows redirects. If retrieving this URL used to work without being redirected, then the site has changed.

Although you can prevent following the redirect within urllib2 (by providing an alternative HTTP handler), I recommend using requests, where you can do:

import requests
r = requests.get('http://www.hearthpwn.com/cards?filter-attack-val=1'
                 '&filter-attack-op=1&display=1', allow_redirects=False)
print(r)

giving you:

<Response [302]>
Anthon
  • 69,918
  • 32
  • 186
  • 246