Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import re
- import os
- from bs4 import BeautifulSoup
- from pathlib import Path
- domain = 'check-you.ru/'
- for root, directories, filenames in os.walk('C:\\cy'):
- for filename in filenames:
- name_path = os.path.join(root)
- name_file = os.path.join(filename)
- f = open(name_path+'\\'+name_file, 'rb')
- file_contents = f.read()
- f.close()
- soup = BeautifulSoup(file_contents, 'html.parser')
- content = soup.find('div', {'class': 'fullstory'})
- tag = soup.find('div', {'class': 'sep tags'})
- str_content = (str(content)+'\n'+str(tag))
- match_url_src = ('/uploads/posts/')
- match_url_src_replace = ('https://'+domain+'uploads/posts/')
- contents_after_re = re.sub(match_url_src, match_url_src_replace, str_content, flags=re.MULTILINE)
- match = ('<div style="display:inline-block; float: left; width: 360px; border: solid 0px black; margin: 10px; margin-top: -10px;">\n'+
- '<div style="position: relative; width: 360px;">\n'+
- '<object data="/player_flv_maxi.swf" height="300" id="0" type="application/x-shockwave-flash" width="360">\n'+
- '<param name="movie" value="/player_flv_maxi.swf"/>\n'+
- '<param name="wmode" value="opaque"/>\n'+
- '<param name="allowFullScreen" value="true"/>\n'+
- '<param name="allowScriptAccess" value="sameDomain"/>\n'+
- '<param name="quality" value="high"/>\n'+
- '<param name="menu" value="true"/>\n'+
- '<param name="autoplay" value="false"/>\n'+
- '<param name="autoload" value="true"/>\n')
- contents_after_re = re.sub(match, ' ', contents_after_re, flags=re.MULTILINE)
- match2 = ('<param name="FlashVars" value="flv=')
- replace_url = ('<a href="https://'+domain)
- contents_after_re = re.sub(match2, replace_url, contents_after_re, flags=re.MULTILINE)
- match3 = ('&width=360&.*?>')
- replace_url3 = ('">Скачать видео</a>')
- contents_after_re = re.sub(match3, replace_url3, contents_after_re, flags=re.MULTILINE)
- match4 = ('</object>\n'+
- '</div></div>')
- contents_after_re = re.sub(match4, '<br>', contents_after_re, flags=re.MULTILINE)
- f = open(name_path+'\\'+name_file, 'w', encoding="utf8")
- ins_0 = "<script type='text/javascript'> $(document).ready(function(){$("
- ins_1 = "'"
- ins_2 = 'a[data-fancybox="fancybox"]'
- ins_3 = "'"
- ins_4 = ").fancybox();})</script><div class='fullstory'>"
- inside_script = ins_0+ins_1+ins_2+ins_3+ins_4
- header = '\n<div style="display:none;"><a href="abouts.html">О проекте</a></div>' \
- '<div class="visible-desktop navbar navbar-fixed-top">' \
- '<div class="navbar-inner">' \
- '<div class="container ">' \
- '<a class="brand pt25" href="../index.html">Check You 18+</a>' \
- '<ul class="nav pt pull-right">' \
- '<li class="">' \
- '</li>' \
- '</ul>' \
- '</div>' \
- '</div>' \
- '</div>'
- add_head = ('<head>\n'+
- '<meta charset="UTF-8">\n'
- '<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">'
- '</head>\n<body>\n'+inside_script+header)
- f.write(add_head)
- f.write(contents_after_re)
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement