Kod:
import requests
import colorama
from colorama import Fore, Back, Style
from lxml import html
from prettytable import PrettyTable
from concurrent.futures import ThreadPoolExecutor
# links.txt dosyasındaki linkleri yükler
colorama.init()
with open("links.txt", "r") as f:
links = f.read().splitlines()
#xpath.txt dosyasından xpath değerini okuma özelliği
#with open("xpath.txt", "r") as f:
# xpath = f.readline().strip()
#xpath = "//a[contains(text(), 'Sonraki Bölüm')]"
xpath = "/html/body/div[1]/div[3]/div/div[1]/div/div[2]/div[4]/div[2]/div[1]/a"
table = PrettyTable()
table.field_names = ["Sonraki Bölüm Var mı?", "Link"]
def process_link(link):
response = requests.get(link)
tree = html.fromstring(response.content)
next_button = tree.xpath(xpath)
if next_button:
next_link = next_button[0].get('href')
return next_link
return None
with ThreadPoolExecutor() as executor:
results = executor.map(process_link, links)
#yeni bölümleri listeleme
for result in results:
if result:
table.add_row(["Sonraki Bölüm Mevcut :", Fore.CYAN + result + Fore.WHITE])
print(table)
# Bölüm değiştirme
while True:
link = input("İzlediğiniz bölümün linkini girin (çıkmak için q) :"+Fore.BLUE)
link = link.replace(" ", "")
if link == 'q':
break
if link in links:
new_b_link = input(Fore.WHITE + "Yeni bölüm linkini girin :"+Fore.BLUE)
new_b_link = new_b_link.replace(" ", "")
index = links.index(link)
links[index] = new_b_link
print(" ")
print(f"{Fore.CYAN}{link}{Fore.WHITE} linki, {Fore.CYAN}{new_b_link}{Fore.WHITE} ile değiştirildi.")
# links.txt dosyasını güncelle
with open("links.txt", "w") as f:
for link in links:
f.write(link + "\n")
else:
print(f"{Fore.RED}{link}{Fore.WHITE} linki, listede bulunamadı.")
Kodlar bu links.txt dosyasındaki linklerden İzlenilen dizinin yeni bölümü var mı? yok mu? onu gösteriyor kısaca kendimce yaptığım birşey bunu c# çevirip gui da eklemek istiyorum o yüzden c# çevirebileceğim program var mı?