My Blog

import requests from bs4 import BeautifulSoup import re def scrape_facebook_posts(): search_query = "SEO backlinks guest post site:facebook.com" google_search_url = f"https://www.google.com/search?q={search_query}&num=10" headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"} response = requests.get(google_search_url, headers=headers) if response.status_code != 200: print("Failed to retrieve search results") return [] soup = BeautifulSoup(response.text, "html.parser") search_results = soup.find_all("a", href=True) facebook_links = [] for link in search_results: url = link["href"] match = re.search(r"https://www\.facebook\.com/[^&]+", url) if match and "profile.php" not in url: # Avoid personal profiles facebook_links.append(match.group(0)) return facebook_links if __name__ == "__main__": print("Fetching relevant Facebook posts...") fb_links = scrape_facebook_posts() if fb_links: print("Relevant Facebook Posts:") for link in fb_links: print(link) else: print("No relevant posts found.")