Skip to main content

Python 包无限制地废弃 facebook 的页面前端

项目描述

Facebook 页面抓取工具

维护 PyPI 许可证 蟒蛇> = 3.6.9

无需注册,无需 API 密钥,无请求数量限制。导入库并照做!

先决条件

  • 网络连接
  • Python 3.6+
  • 您的机器上安装了 Chrome 或 Firefox 浏览器


安装:

从源安装:

git clone https://github.com/shaikhsajid1111/facebook_page_scraper

项目目录内部

python3 setup.py install

使用 pypi 安装

pip3 install facebook-page-scraper


如何使用?

#import Facebook_scraper class from facebook_page_scraper
from facebook_page_scraper import Facebook_scraper

#instantiate the Facebook_scraper class

page_name = "metaai"
posts_count = 10
browser = "firefox"
proxy = "IP:PORT" #if proxy requires authentication then user:password@IP:PORT
timeout = 600 #600 seconds
headless = True
meta_ai = Facebook_scraper(page_name, posts_count, browser, proxy=proxy, timeout=timeout, headless=headless)

Facebook_scraper(page_name, posts_count, browser, proxy, timeout, headless) 类参数

参数名称 参数类型 描述
page_name 细绳 脸书页面的名称
post_count 整数 要报废的帖子数,如果未通过,默认为 10
浏览器 细绳 使用哪个浏览器,chrome 或 firefox。如果没有通过,默认是chrome
代理(可选) 细绳 可选参数,如果用户想设置代理,如果代理需要认证,那么格式将是 user:password@IP:PORT
暂停 整数 机器人应该运行的最长时间。如果不通过,默认超时设置为10分钟
无头 布尔值 是否以无头模式运行浏览器?默认为真



完成实例化了吗?让刮痧开始吧!


对于JSON格式的帖子数据:

#call the scrap_to_json() method

json_data = meta_ai.scrap_to_json()
print(json_data)

输出:

{
  "2024182624425347": {
    "name": "Meta AI",
    "shares": 0,
    "reactions": {
      "likes": 154,
      "loves": 19,
      "wow": 0,
      "cares": 0,
      "sad": 0,
      "angry": 0,
      "haha": 0
    },
    "reaction_count": 173,
    "comments": 2,
    "content": "We’ve built data2vec, the first general high-performance self-supervised algorithm for speech, vision, and text. We applied it to different modalities and found it matches or outperforms the best self-supervised algorithms. We hope this brings us closer to a world where computers can learn to solve many different tasks without supervision. Learn more and get the code:  https://ai.facebook.com/…/the-first-high-performance-self-s…",
    "posted_on": "2022-01-20T22:43:35",
    "video": "",
    "image": [
      "https://scontent-bom1-2.xx.fbcdn.net/v/t39.30808-6/s480x480/272147088_2024182621092014_6532581039236849529_n.jpg?_nc_cat=100&ccb=1-5&_nc_sid=8024bb&_nc_ohc=j4_1PAndJTIAX82OLNq&_nc_ht=scontent-bom1-2.xx&oh=00_AT9us__TvC9eYBqRyQEwEtYSit9r2UKYg0gFoRK7Efrhyw&oe=61F17B71"
    ],
    "post_url": "https://www.facebook.com/MetaAI/photos/a.360372474139712/2024182624425347/?type=3&__xts__%5B0%5D=68.ARBoSaQ-pAC_ApucZNHZ6R-BI3YUSjH4sXsfdZRQ2zZFOwgWGhjt6dmg0VOcmGCLhSFyXpecOY9g1A94vrzU_T-GtYFagqDkJjHuhoyPW2vnkn7fvfzx-ql7fsBYxL5DgQVSsiC1cPoycdCvHmi6BV5Sc4fKADdgDhdFvVvr-ttzXG1ng2DbLzU-XfSes7SAnrPs-gxjODPKJ7AdqkqkSQJ4HrsLgxMgcLFdCsE6feWL7rXjptVWegMVMthhJNVqO0JHu986XBfKKqB60aBFvyAzTSEwJD6o72GtnyzQ-BcH7JxmLtb2_A&__tn__=-R"
  }, ...

}

JSON格式的输出结构:

{
    "id": {
        "name": string,
        "shares": integer,
        "reactions": {
            "likes": integer,
            "loves": integer,
            "wow": integer,
            "cares": integer,
            "sad": integer,
            "angry": integer,
            "haha": integer
        },
        "reaction_count": integer,
        "comments": integer,
        "content": string,
        "video" : string,
        "image" : list,
        "posted_on": datetime,  //string containing datetime in ISO 8601
        "post_url": string
    }
}



用于将帖子的数据直接保存到CSV文件

#call scrap_to_csv(filename,directory) method


filename = "data_file"  #file name without CSV extension,where data will be saved
directory = "E:\data" #directory where CSV file will be saved
meta_ai.scrap_to_csv(filename, directory)

内容data_file.csv

id,name,shares,likes,loves,wow,cares,sad,angry,haha,reactions_count,comments,content,posted_on,video,image,post_url
2024182624425347,Meta AI,0,154,19,0,0,0,0,0,173,2,"We’ve built data2vec, the first general high-performance self-supervised algorithm for speech, vision, and text. We applied it to different modalities and found it matches or outperforms the best self-supervised algorithms. We hope this brings us closer to a world where computers can learn to solve many different tasks without supervision. Learn more and get the code:  https://ai.facebook.com/…/the-first-high-performance-self-s…",2022-01-20T22:43:35,,https://scontent-bom1-2.xx.fbcdn.net/v/t39.30808-6/s480x480/272147088_2024182621092014_6532581039236849529_n.jpg?_nc_cat=100&ccb=1-5&_nc_sid=8024bb&_nc_ohc=j4_1PAndJTIAX82OLNq&_nc_ht=scontent-bom1-2.xx&oh=00_AT9us__TvC9eYBqRyQEwEtYSit9r2UKYg0gFoRK7Efrhyw&oe=61F17B71,https://www.facebook.com/MetaAI/photos/a.360372474139712/2024182624425347/?type=3&__xts__%5B0%5D=68.ARAse4eiZmZQDOZumNZEDR0tQkE5B6g50K6S66JJPccb-KaWJWg6Yz4v19BQFSZRMd04MeBmV24VqvqMB3oyjAwMDJUtpmgkMiITtSP8HOgy8QEx_vFlq1j-UEImZkzeEgSAJYINndnR5aSQn0GUwL54L3x2BsxEqL1lElL7SnHfTVvIFUDyNfAqUWIsXrkI8X5KjoDchUj7aHRga1HB5EE0x60dZcHogUMb1sJDRmKCcx8xisRgk5XzdZKCQDDdEkUqN-Ch9_NYTMtxlchz1KfR0w9wRt8y9l7E7BNhfLrmm4qyxo-ZpA&__tn__=-R
...



方法的参数 scrap_to_csv(filename, directory)

参数名称 参数类型 描述
文件名 细绳 将保存帖子数据的 CSV 文件的名称
目录 细绳 必须存储 CSV 文件的目录。



输出键:

钥匙 类型 描述
ID 细绳 Post Identifier(在字符串中转换的整数)
姓名 细绳 页面名称
分享 整数 分享帖子数
反应 字典 包含作为键的反应和作为值的计数的字典。键 => ["likes","loves","wow","cares","sad","angry","haha"]
反应计数 整数 帖子的总反应数
注释 整数 帖子的评论数
内容 细绳 帖子内容为文本
视频 细绳 该帖子中出现的视频网址
图片 列表 包含帖子中所有图像的 URL 的列表
发表于 约会时间 发帖时间(ISO 8601 格式)
post_url 细绳 该帖子的网址


隐私

该抓取工具仅抓取未经身份验证的用户可用的公共数据,并且不具备抓取任何私有数据的能力。



科技

该项目使用不同的库来正常工作。



如果您遇到任何异常情况,请随时在此处创建问题

执照

麻省理工学院

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

facebook_page_scraper-3.0.2.tar.gz (20.2 kB 查看哈希)

已上传 source