Advertisement
shoaib-santo

Backlink Indexing Checker [Scraping Robot]

Jan 11th, 2025
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.68 KB | None | 0 0
  1. !pip install requests
  2.  
  3. from requests import get
  4. import re
  5. import csv
  6.  
  7. # Upload your text file with backlinks
  8. from google.colab import files
  9. uploaded = files.upload()
  10.  
  11. # Read backlinks from the uploaded file
  12. backlinks_file = list(uploaded.keys())[0]  # Get the uploaded file name
  13. with open(backlinks_file, 'r') as file:
  14.     backlinks = file.read().splitlines()
  15.  
  16. # Prepare the output CSV file
  17. output_file = "backlink_index_status.csv"
  18.  
  19. # Define your ScrapingRobot API token
  20. api_token = "d6adcc0b-b8a4-47e0-a00c-23e9c33f0633"
  21.  
  22. # Initialize the CSV file with headers
  23. with open(output_file, 'w', newline='') as csvfile:
  24.     csvwriter = csv.writer(csvfile)
  25.     csvwriter.writerow(["Backlink", "Index Status"])
  26.  
  27. # Check indexing for each backlink and write to the CSV file
  28. for backlink in backlinks:
  29.     api_key = f"https://api.scrapingrobot.com/?token={api_token}&url=https://www.google.com/search?q=site:{backlink}"
  30.     try:
  31.         response = get(api_key).json().get('result')
  32.         match = re.search(r'About \d+ results', response)
  33.         if match:
  34.             num_results = int(match.group().split(' ')[1])
  35.             index_status = "Indexed" if num_results >= 1 else "Not Indexed"
  36.             print(f"{backlink} Index Status: {index_status}")
  37.         else:
  38.             index_status = "Not Indexed"
  39.     except Exception as e:
  40.         index_status = "Error"
  41.  
  42.     # Write the backlink and its status to the CSV
  43.     with open(output_file, 'a', newline='') as csvfile:
  44.         csvwriter = csv.writer(csvfile)
  45.         csvwriter.writerow([backlink, index_status])
  46.  
  47. print(f"Index status has been saved to {output_file}")
  48.  
  49. # Download the CSV file
  50. files.download(output_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement