Web scraping,Data minig veya Otomosyon yazanların işine yarabilecek bir fonskiyonu sizlerle paylaşıyorum.
Verilen listeyi URL:USERNAME
ASSWORD olarak ayırır.
Verilen listeyi URL:USERNAME
Python:
import re
import chardet
def splitdo(UPL):
splitdata = []
line = UPL.strip()
if not line:
return splitdata
pattern = r'^(https?://[\S:]+|[\S:]+):([^:]+):(.+)$'
match = re.match(pattern, line)
if match:
url = match.group(1)
username = match.group(2)
password = match.group(3)
if not url.startswith("http"):
url = "https://" + url.lstrip("//")
splitdata.append((url, username, password))
else:
print(f"Satır eşleşmedi: {line}")
return splitdata
def Detectchar(FileName):
with open(FileName, "rb") as file:
read = file.read()
detect = chardet.detect(read)
return detect['encoding']
#kullanımı
filename="UPL.txt"
with open(filename, "r", encoding=charset, errors='ignore') as file:
for line in file:
result = splitdo(line)
if result:
url, username, password = result[0]
#diğer işlemler........
