Reputation:
I can get requests.get(web).content
of any website except one, www.bundukhansweets.pk
.
import requests
web = "http://umararfeen.com"
req = requests.get(web).status_code
print req
Result: 200
But when I try to open a website that has www.
at the start it says 403
(Forbidden). I even tried "http://www."+website
and "www."+website
:
import requests
web = "http://bundukhansweets.pk"
print requests.get(web).status_code
Result: 403
I even tried urllib2
but failed.
Upvotes: 1
Views: 301
Reputation: 1966
you are missing headers
import requests
web = "http://bundukhansweets.pk"
hdr = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding': 'gzip,deflate,sdch',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive'
}
print requests.get(web, headers=hdr).status_code
this will work
Upvotes: 1