Advertisement
Najeebsk

SCRAP-EXT-PV.py

Jan 9th, 2024
715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.99 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import ttk
  3. import requests
  4. from bs4 import BeautifulSoup
  5. from urllib.parse import urljoin
  6.  
  7. class WebScraperApp:
  8.     def __init__(self, root):
  9.         self.root = root
  10.         self.root.title("avi/mp4/mp3/png/jpg/m3u/m3u8 Web Scraper")
  11.  
  12.         self.url_label = ttk.Label(root, text="Enter URL:")
  13.         self.url_entry = ttk.Entry(root, width=50)
  14.         self.scrape_button = ttk.Button(root, text="Scrape", command=self.scrape)
  15.  
  16.         self.result_text = tk.Text(root, height=36, width=100)
  17.         self.result_text.insert(tk.END, "Scraped URLs will be displayed here.")
  18.  
  19.         self.url_label.grid(row=0, column=0, pady=5)
  20.         self.url_entry.grid(row=0, column=1, pady=5)
  21.         self.scrape_button.grid(row=0, column=2, pady=5)
  22.         self.result_text.grid(row=1, column=0, columnspan=3, pady=10)
  23.  
  24.     def scrape(self):
  25.         url = self.url_entry.get()
  26.         if not url:
  27.             return
  28.  
  29.         try:
  30.             response = requests.get(url)
  31.             response.raise_for_status()
  32.         except requests.exceptions.RequestException as e:
  33.             self.display_result(f"Error: {e}")
  34.             return
  35.  
  36.         soup = BeautifulSoup(response.content, 'html.parser')
  37.         links = [a['href'] for a in soup.find_all('a', href=True) if a['href'].endswith(('.m3u', '.m3u8', '.mp4', '.mp3', '.avi', '.jpg', '.png'))]
  38.  
  39.         if links:
  40.             absolute_links = [urljoin(url, link) for link in links]
  41.             result_text = "\n".join(absolute_links)
  42.             self.display_result(result_text)
  43.         else:
  44.             self.display_result("No avi/mp4/mp3/png/jpg/m3u/m3u8 links found on the page.")
  45.  
  46.     def display_result(self, text):
  47.         self.result_text.config(state=tk.NORMAL)
  48.         self.result_text.delete(1.0, tk.END)
  49.         self.result_text.insert(tk.END, text)
  50.         self.result_text.config(state=tk.DISABLED)
  51.  
  52. if __name__ == "__main__":
  53.     root = tk.Tk()
  54.     app = WebScraperApp(root)
  55.     root.mainloop()
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement