Guest User

`ent-name` comparison tool

a guest
Nov 5th, 2025
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. import argparse
  2. import requests
  3. from bs4 import BeautifulSoup
  4.  
  5. def get_ent_names(url):
  6.     response = requests.get(url)
  7.     response.raise_for_status()
  8.     soup = BeautifulSoup(response.text, 'html.parser')
  9.  
  10.     names = []
  11.     for el in soup.find_all(class_='ent-name'):
  12.         text = el.get_text(strip=True)
  13.         if text and text not in names:
  14.             names.append(text)
  15.         if len(names) >= limit:
  16.             break
  17.     return names
  18.  
  19. def compare_ent_names(url1, url2):
  20.     names1 = get_ent_names(url1)
  21.     names2 = get_ent_names(url2)
  22.  
  23.     only_in_1 = [n for n in names1 if n not in names2]
  24.     only_in_2 = [n for n in names2 if n not in names1]
  25.     in_both   = [n for n in names1 if n in names2]
  26.  
  27.     def fmt(lst):
  28.         return ", ".join(lst) if lst else "(none)"
  29.  
  30.     print(f"\n--- Only in URL 1 ({url1}) ---")
  31.     print(fmt(only_in_1))
  32.  
  33.     print(f"\n--- Only in URL 2 ({url2}) ---")
  34.     print(fmt(only_in_2))
  35.  
  36.     print(f"\n--- In both ---")
  37.     print(fmt(in_both))
  38.  
  39. def main():
  40.     parser = argparse.ArgumentParser(
  41.         description="Compare .ent-name elements between two webpages."
  42.     )
  43.     parser.add_argument("url1", help="First URL with `.ent-name`s to compare")
  44.     parser.add_argument("url2", help="Second URL with `.ent-name`s to compare")
  45.     args = parser.parse_args()
  46.  
  47.     compare_ent_names(args.url1, args.url2)
  48.  
  49. if __name__ == "__main__":
  50.     main()
  51.  
Advertisement
Add Comment
Please, Sign In to add comment