0

I attempted to fetch data from an URL and I noticed that URL is censure in my country. So I enable proxy and config Pycharm to use that. In testing connection, connecting to that URL is successful but still, in running the code,

I got this Error: HTTPError: HTTP Error 403: Forbidden

I circulated the web for the answer and I got sth like following:

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-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
   'Accept-Encoding': 'none',
   'Accept-Language': 'en-US,en;q=0.8',
   'Connection': 'keep-alive'}

req = urllib2.Request(site, headers=hdr)

But it was not useful!

My code is the following:

import urllib2 from bs4 import BeautifulSoup

def getAllDoxyPost(url, links):

request = urllib2.Request(url)
response = urllib2.urlopen(request)
soup = BeautifulSoup(response)

for a in soup.find_all('a'):
    try:
        url = a['href']
        title = a['title']
        if title == 'Older Posts':
            print title, url
            links.append(url)
            getAllDoxyPost(url, links)
    except:
        title = " "
return 

blogUrl = "http://doxydonkey.blogspot.in"
links = []
getAllDoxyPost(blogUrl, links)
always-a-learner
  • 3,671
  • 10
  • 41
  • 81
Soheil Pourbafrani
  • 3,249
  • 3
  • 32
  • 69

0 Answers0