test.py 700 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/python3
  2. from bs4 import BeautifulSoup;
  3. import requests;
  4. import urllib;
  5. import re;
  6. def dosyayaYaz(url):
  7. source = requests.get(url);
  8. icerik = source.content;
  9. crawler = BeautifulSoup(icerik,"html.parser");
  10. dosya = open('/tmp/{}.txt'.format(crawler.html.head.title.string),'a');
  11. sozlerHam = crawler.find('div', {"class" : "reading"});
  12. sozler = str(sozlerHam);
  13. sarkiSozleri = re.sub('<.*?>', '\n', sozler);
  14. sarkiSozleri = re.sub('.*[;:]', '\n', sarkiSozleri);
  15. dosya.write(sarkiSozleri);
  16. return 1;
  17. def main():
  18. if htmlCek("https://www.rapsozler.com/rota-ultimatif-sarki-sozu/") == 1:
  19. print ("Dosyaya yazma başarılı.");
  20. else:
  21. print ("Dosyaya yazma başarısız.");
  22. main();