Advertisement
Guest User

check-you

a guest
Dec 22nd, 2018
1,130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.10 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import re
  4. import os
  5. from bs4 import BeautifulSoup
  6. from pathlib import Path
  7. domain = 'check-you.ru/'
  8. for root, directories, filenames in os.walk('C:\\cy'):
  9.     for filename in filenames:
  10.         name_path = os.path.join(root)
  11.         name_file = os.path.join(filename)
  12.         f = open(name_path+'\\'+name_file, 'rb')
  13.         file_contents = f.read()
  14.         f.close()
  15.         soup = BeautifulSoup(file_contents, 'html.parser')
  16.         content = soup.find('div', {'class': 'fullstory'})
  17.         tag = soup.find('div', {'class': 'sep tags'})
  18.         str_content = (str(content)+'\n'+str(tag))
  19.         match_url_src = ('/uploads/posts/')
  20.         match_url_src_replace = ('https://'+domain+'uploads/posts/')
  21.         contents_after_re = re.sub(match_url_src, match_url_src_replace, str_content, flags=re.MULTILINE)
  22.         match = ('<div style="display:inline-block; float: left; width: 360px; border: solid 0px black; margin: 10px; margin-top: -10px;">\n'+
  23.              '<div style="position: relative; width: 360px;">\n'+
  24.              '<object data="/player_flv_maxi.swf" height="300" id="0" type="application/x-shockwave-flash" width="360">\n'+
  25.              '<param name="movie" value="/player_flv_maxi.swf"/>\n'+
  26.              '<param name="wmode" value="opaque"/>\n'+
  27.              '<param name="allowFullScreen" value="true"/>\n'+
  28.              '<param name="allowScriptAccess" value="sameDomain"/>\n'+
  29.              '<param name="quality" value="high"/>\n'+
  30.              '<param name="menu" value="true"/>\n'+
  31.              '<param name="autoplay" value="false"/>\n'+
  32.              '<param name="autoload" value="true"/>\n')
  33.         contents_after_re = re.sub(match, ' ', contents_after_re, flags=re.MULTILINE)
  34.         match2 = ('<param name="FlashVars" value="flv=')
  35.         replace_url = ('<a href="https://'+domain)
  36.         contents_after_re = re.sub(match2, replace_url, contents_after_re, flags=re.MULTILINE)
  37.         match3 = ('&amp;width=360&amp;.*?>')
  38.         replace_url3 = ('">Скачать видео</a>')
  39.         contents_after_re = re.sub(match3, replace_url3, contents_after_re, flags=re.MULTILINE)
  40.         match4 = ('</object>\n'+
  41.                     '</div></div>')
  42.         contents_after_re = re.sub(match4, '<br>', contents_after_re, flags=re.MULTILINE)
  43.         f = open(name_path+'\\'+name_file, 'w', encoding="utf8")
  44.         ins_0 = "<script type='text/javascript'>    $(document).ready(function(){$("
  45.         ins_1 = "'"
  46.         ins_2 = 'a[data-fancybox="fancybox"]'
  47.         ins_3 = "'"
  48.         ins_4 = ").fancybox();})</script><div class='fullstory'>"
  49.         inside_script = ins_0+ins_1+ins_2+ins_3+ins_4
  50.         header = '\n<div style="display:none;"><a href="abouts.html">О проекте</a></div>' \
  51.                  '<div class="visible-desktop navbar navbar-fixed-top">' \
  52.                  '<div class="navbar-inner">' \
  53.                  '<div class="container ">' \
  54.                  '<a class="brand pt25" href="../index.html">Check You 18+</a>' \
  55.                  '<ul class="nav pt pull-right">' \
  56.                  '<li class="">' \
  57.                  '</li>' \
  58.                  '</ul>' \
  59.                  '</div>' \
  60.                  '</div>' \
  61.                  '</div>'
  62.         add_head = ('<head>\n'+
  63.         '<meta charset="UTF-8">\n'
  64.         '<script type="text/javascript" src="../engine/classes/js/jquery_002.js"></script><script type="text/javascript" src="../engine/classes/js/jquery.js"></script><script src="../templates/city-skyline/source/jquery.fancybox.pack.2.1.7.js?v=2.1.7"></script><link href="../templates/city-skyline/assets/css/bootstrap.css?z1" rel="stylesheet"><link href="../templates/city-skyline/assets/css/bootstrap-responsive.css?z1" rel="stylesheet"><link href="../templates/city-skyline/assets/css/city.css?z1z12" rel="stylesheet"><link href="../templates/city-skyline/style/engine.css?z1" rel="stylesheet"><link href="../templates/city-skyline/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet">'
  65.         '</head>\n<body>\n'+inside_script+header)
  66.  
  67.         f.write(add_head)
  68.         f.write(contents_after_re)
  69.         f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement