urllib2 Error 403: Forbidden

后端 未结 2 620
生来不讨喜
生来不讨喜 2021-01-28 06:10

I have posted to this site and received really helpful guidance, i return with another question.

Where have i gone wrong here, I was prettty sure this is what is require

2条回答
  •  不思量自难忘°
    2021-01-28 06:29

    Actually the problem is that they block everyone who doesn't have a user-agent

    import urllib2
    
    request = urllib2.Request("http://www.cmegroup.com/trading/energy/natural-gas/natural-gas.html", None, {'User-Agent': 'Mozilla/5.0'})
    content = urllib2.urlopen(request).read()
    splitted_page = content.split("", 1);
    splitted_page = splitted_page[1].split("", 1)
    print splitted_page[0]
    

提交回复
热议问题