scrapeFB.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:FBscraper 作者: precognox-admin 项目源码 文件源码
def __init__(self, access_token, db_path, id_list):
        """Connects to Facebook Graph API and creates an SQLite database with four tables for Posts, Comments,
        Post_likes and People if not exists.

        Takes three arguments:
        access_token: your own Facebook access token that you can get on https://developers.facebook.com/tools/explorer/
        db_path: the path of the SQLite database where you want to store the data
        id_list: ID's of the Facebook pages you want to scrape
        """
        self.access_token = access_token
        self.db_path = db_path
        self.id_list = id_list

        g = facebook.GraphAPI(self.access_token, version='2.3')
        self.g = g

        # connect to database
        con = lite.connect(self.db_path)
        self.con = con

        with con:
            # create cursor to the database
            cur = con.cursor()
            self.cur = cur
            # create tables for posts, comments, post likes and people if not exists
            cur.execute(
                "CREATE TABLE IF NOT EXISTS Posts(post_id TEXT PRIMARY KEY, status_id TEXT, content TEXT, "
                "person_hash_id TEXT, published_date TEXT, last_comment_date TEXT, post_type TEXT, status_type TEXT, "
                "post_link TEXT, link TEXT, video_link TEXT, picture_link TEXT, link_name TEXT, link_caption TEXT, "
                "link_description TEXT, comment_count INTEGER, share_count INTEGER, like_count INTEGER, "
                "love_count INTEGER, wow_count INTEGER, haha_count INTEGER, sad_count INTEGER, angry_count INTEGER, "
                "mentions_count INTEGER, mentions TEXT, location TEXT, date_inserted TEXT)")
            cur.execute(
                "CREATE TABLE IF NOT EXISTS Comments(comment_id TEXT PRIMARY KEY, person_hash_id TEXT, post_id TEXT, "
                "comment_content TEXT, comment_date TEXT, like_count INTEGER)")
            cur.execute(
                "CREATE TABLE IF NOT EXISTS Post_likes(like_id TEXT PRIMARY KEY, person_hash_id TEXT, post_id TEXT)")
            cur.execute(
                "CREATE TABLE IF NOT EXISTS People(person_hash_id TEXT PRIMARY KEY, person_id TEXT, person_name TEXT)")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号