通过Facebook Marketing API获取Facebook的最新广告类型及其要求

问题描述

我一直在浏览https://developers.facebook.com/docs/marketing-api/上的facebook api文档,但尚未找到解决方案。我只想获取页面上列出的Facebook最新广告类型的列表:https://www.facebook.com/business/ads-guide以及每种广告的规格。是否可以通过API?

请澄清一下,我不想访问特定Facebook帐户的广告或广告系列。我只希望能够通过API动态获取Facebook最新的广告类型和每种广告类型的要求,而不必将此信息存储在数据库中,从而避免手动保持最新信息。

我意识到这不是一个特定的编码问题,但是如果可以的话,在将我指向适当资源方面的任何帮助将不胜感激。

解决方法

我认为您不仅需要API,还需要简单的网络抓取工具-例如requestsBeautifulSoup-有很多tutorials关于如何进行网络连接的信息-scrape。

  1. 以HTML格式浏览网站-这样您就会知道要搜索的内容

  2. 尝试在请求输出中找到相同的HTML元素-对于您的示例,看起来像这样:

    import requests
    from bs4 import BeautifulSoup
    
    
    data = requests.get('https://www.facebook.com/business/ads-guide',verify=False)
    
    soup = BeautifulSoup(data.text,'html.parser')
    # after looking at the page you can see that this is the class name that is used for the ad type tags
    relevant_fields = soup.find_all(class_="_3tms _80jr _8xn- _7oxw _34g8")[1:]
    # or optionally you can search for the heading3 types
    #relevant_fields = soup.find_all('h3')[1:]
    
    print([a.get_text() for a in relevant_fields])
    

enter image description here