有问题试图用Python刮掉Facebook页面

时间:2016-08-29 13:43:25

标签: python facebook web-scraping

我试过这段代码

import urllib2
import json

def main():
    list_companies = ["walmart", "cisco", "pepsi", "facebook"]
    graph_url = "https://graph.facebook.com/"

    for company in list_companies:
        current_page = graph_url + company

        web_response = urllib2.urlopen(current_page)
        readable_page = web_response.read()
        json_fbpage = json.loads(readable_page)


        print company + " page"
        print json_fbpage["id"]
        print json_fbpage["likes"]
        print json_fbpage["talking_about_count"]
        print json_fbpage["username"]
    print "            "

if __name__ == "__main__":
    main()

但最终出现了这个错误

Traceback (most recent call last):
  File "C:\Users\The Blood\Documents\CITAD HATESPEECH SCRAPER\NEW.py", line 24, in <module>
    main()
  File "C:\Users\The Blood\Documents\CITAD HATESPEECH SCRAPER\NEW.py", line 11, in main
    web_response = urllib2.urlopen(current_page)
  File "G:\Python27\lib\urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "G:\Python27\lib\urllib2.py", line 435, in open
    response = meth(req, response)
  File "G:\Python27\lib\urllib2.py", line 548, in http_response
    'http', request, response, code, msg, hdrs)
  File "G:\Python27\lib\urllib2.py", line 473, in error
    return self._call_chain(*args)
  File "G:\Python27\lib\urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "G:\Python27\lib\urllib2.py", line 556, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 400: Bad Request

我需要抬头。

由于

0 个答案:

没有答案