2

I have been looking through the facebook api documentation at https://developers.facebook.com/docs/marketing-api/, but have yet to find a solution for this. I simply want to get a list of facebook's latest ad types that are listed on this page: https://www.facebook.com/business/ads-guide as well as the specifications for each one. Is this possible via API?

Just to clarify, I don't want to access a specific facebook account's ads or campaigns. I just want to dynamically be able to fetch facebook's latest ad types and each ad types requirements via API without having to store this information within my database so as to avoid keeping up to date information manually.

I realize this isn't a specific coding problem, but any help in pointing me to the appropriate resources if this is possible would be much appreciated.

jmchauv
  • 137
  • 14

1 Answers1

1

I think you don't need the API just the simple web-scraping tools that are out there - like requests and BeautifulSoup - there are lots of tutorials about how to web-scrape.

  1. Explore the website in its HTML - so you'd know what you are looking for

  2. Try to find the same HTML elements in your requests output -for your example that would looks something like this:

    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

Anna Semjén
  • 647
  • 4
  • 14
  • I'm not sure this solves the problem in a fool-proof way. What if facebook changes the way they present this info on this page? I'd rather be able to connect via an api and just return the data straight up than scrubbing a page that could possibly be changed in the future. Please correct me if I'm wrong in my assumption, but if FB changes the way they display the info on this page, this would no longer work. – jmchauv Dec 10 '20 at 20:30
  • The page you are scraping is not a ‘data provider’ page - just a random website which happens to be a Fb website. LinkedIn has APIs for its users and facebook as APIs to manage ‘query’ and work with ads. There isn’t a data element here - I think you can teach an AI possibly to go on the website and figure out where those tags are once they get changed...or wait for smarter responses – Anna Semjén Dec 10 '20 at 21:13