SHARE
    TWEET
    Najeebsk

    IPTV-LINK-EXTRAC-ONLINE.pyw

    Jun 22nd, 2024
    778
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    Python 6.32 KB | None | 0 0
    1. import tkinter as tk
    2. from tkinter import ttk, messagebox
    3. from tkinter.scrolledtext import ScrolledText
    4. import requests
    5. from bs4 import BeautifulSoup
    6. from urllib.parse import urljoin
    7. import subprocess
    8. class LinkScraperGUI:
    9. def __init__(self, master):
    10. self.master = master
    11. self.master.title("Web Links Scraper and Save Text")
    12. self.master.geometry("800x600")
    13. # Style configuration
    14. self.style = ttk.Style()
    15. self.style.theme_use("clam") # Use 'clam' theme for modern look
    16. self.style.configure("TLabel", font=("Helvetica", 12))
    17. self.style.configure("TButton", font=("Helvetica", 12), background="#4CAF50", foreground="white")
    18. self.style.configure("TEntry", font=("Helvetica", 12), padding=5)
    19. self.style.configure("TScrollbar", gripcount=0, background="#f1f1f1")
    20. # URL entry frame
    21. self.url_frame = ttk.Frame(master)
    22. self.url_frame.pack(pady=10, padx=10, fill=tk.X)
    23. self.url_label = ttk.Label(self.url_frame, text="Enter URL:")
    24. self.url_label.pack(side=tk.LEFT, padx=(0, 10))
    25. self.url_entry = ttk.Entry(self.url_frame, width=70)
    26. self.url_entry.pack(side=tk.LEFT, fill=tk.X, expand=True)
    27. self.scrape_button = ttk.Button(self.url_frame, text="Scrape Links", command=self.scrape_links)
    28. self.scrape_button.pack(side=tk.LEFT, padx=(10, 0))
    29. # Links editable text frame
    30. self.links_frame = ttk.Frame(master)
    31. self.links_frame.pack(pady=10, padx=10, fill=tk.BOTH, expand=True)
    32. self.links_text = ScrolledText(self.links_frame, width=100, height=10, font=("Helvetica", 12))
    33. self.links_text.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
    34. self.listbox_scrollbar = ttk.Scrollbar(self.links_frame, orient=tk.VERTICAL, command=self.links_text.yview)
    35. self.listbox_scrollbar.pack(side=tk.LEFT, fill=tk.Y)
    36. self.links_text.config(yscrollcommand=self.listbox_scrollbar.set)
    37. self.links_text.bind("<Double-1>", self.open_in_vlc)
    38. # Scrape selected link button
    39. self.scrape_selected_button = ttk.Button(master, text="Scrape Selected Link", command=self.scrape_selected_link)
    40. self.scrape_selected_button.pack(pady=10)
    41. # Result text frame
    42. self.result_frame = ttk.Frame(master)
    43. self.result_frame.pack(pady=10, padx=10, fill=tk.BOTH, expand=True)
    44. self.result_text = ScrolledText(self.result_frame, width=100, height=10, font=("Helvetica", 12))
    45. self.result_text.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
    46. self.text_scrollbar = ttk.Scrollbar(self.result_frame, orient=tk.VERTICAL, command=self.result_text.yview)
    47. self.text_scrollbar.pack(side=tk.LEFT, fill=tk.Y)
    48. self.result_text.config(yscrollcommand=self.text_scrollbar.set)
    49. self.result_text.bind("<Double-1>", self.open_in_vlc)
    50. # Save results button
    51. self.save_button = ttk.Button(master, text="Save Results", command=self.save_results)
    52. self.save_button.pack(pady=10)
    53. def scrape_links(self):
    54. url = self.url_entry.get()
    55. if not url:
    56. messagebox.showerror("Error", "Please enter a valid URL.")
    57. return
    58. try:
    59. response = requests.get(url)
    60. response.raise_for_status()
    61. except requests.exceptions.RequestException as e:
    62. messagebox.showerror("Error", f"Error fetching URL: {e}")
    63. return
    64. soup = BeautifulSoup(response.text, 'html.parser')
    65. # Extract all links from the webpage
    66. links = soup.find_all('a', href=True)
    67. if not links:
    68. messagebox.showinfo("Info", "No links found on the given URL.")
    69. return
    70. # Ensure the links are complete URLs
    71. complete_links = [urljoin(url, link['href']) for link in links]
    72. # Clear the ScrolledText before inserting new links
    73. self.links_text.delete(1.0, tk.END)
    74. # Insert links into the ScrolledText
    75. for link in complete_links:
    76. self.links_text.insert(tk.END, link + '\n')
    77. def scrape_selected_link(self):
    78. selected_text = self.links_text.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
    79. if not selected_text:
    80. messagebox.showerror("Error", "Please select a link from the text.")
    81. return
    82. try:
    83. response = requests.get(selected_text)
    84. response.raise_for_status()
    85. except requests.exceptions.RequestException as e:
    86. messagebox.showerror("Error", f"Error fetching URL: {e}")
    87. return
    88. soup = BeautifulSoup(response.text, 'html.parser')
    89. # Extract all links from the selected webpage
    90. links = soup.find_all('a', href=True)
    91. if not links:
    92. messagebox.showinfo("Info", "No links found on the selected URL.")
    93. return
    94. # Ensure the links are complete URLs
    95. complete_links = [urljoin(selected_text, link['href']) for link in links]
    96. # Display results in the ScrolledText widget
    97. self.result_text.delete(1.0, tk.END)
    98. for link in complete_links:
    99. self.result_text.insert(tk.END, link + '\n')
    100. def save_results(self):
    101. file_path = "Files-Links.txt"
    102. with open(file_path, 'a', encoding='utf-8') as file:
    103. links = self.result_text.get(1.0, tk.END).strip()
    104. file.write(links + '\n\n') # Add a blank line after each set of links
    105. messagebox.showinfo("Success", f"Links appended to {file_path}")
    106. def open_in_vlc(self, event):
    107. try:
    108. widget = event.widget
    109. index = widget.index("@%s,%s" % (event.x, event.y))
    110. line_start = f"{index.split('.')[0]}.0"
    111. line_end = f"{index.split('.')[0]}.end"
    112. selected_text = widget.get(line_start, line_end).strip()
    113. if not selected_text:
    114. messagebox.showerror("Error", "Please select a URL.")
    115. return
    116. vlc_path = r"C:\Program Files\VideoLAN\VLC\vlc.exe"
    117. subprocess.Popen([vlc_path, selected_text])
    118. except Exception as e:
    119. messagebox.showerror("Error", f"Failed to open VLC: {e}")
    120. if __name__ == "__main__":
    121. root = tk.Tk()
    122. app = LinkScraperGUI(root)
    123. root.mainloop()
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /