123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- #!/usr/bin/python3
- import os
- import codecs
- import dataset
- def extract_comp(fname):
- resultstr=""
- fr=codecs.open(fname,'r','utf-8')
- lines=fr.readlines()
- inloop=False
- for l in lines:
- if inloop:
- if '<script async defer crossorigin="anonymous" src="https://connect.facebook' in l:
- # break
- #<script async="" defer="" crossorigin="anonymous" src="https://connect.facebook.net/zh_TW/sdk.js#xfbml=1&version=v9.0" nonce=""></script>
- # if '/article>' in l:
- # resultstr+=l
- break
-
- resultstr+=l+"\n"
- # if 'class="dAbout"' in l and 'article' in l:
- if 'row justify-content-between mt-5' in l:
- inloop=True
- resultstr+=l+"\n"
- continue
- return resultstr
- #<script async defer crossorigin="anonymous" src="https://connect.facebook.net/
- def proc_file(fname,fname2,compcontent):
- fr=codecs.open(fname,'r','utf-8')
- fw=codecs.open(fname2,'w','utf-8')
- lines=fr.readlines()
- scriptflag=False
- for l in lines:
- # <div class="row mt-5" id="row">
- if 'div' in l and 'class' in l and 'row mt-5' in l and 'id="row"' in l:
- fw.write('<div class="row mt-5" id="row_company" style="display:none">\n')
- fw.write(compcontent)
- fw.write('</div>\n')
- fw.write('<div class="row mt-5" id="row_intro">\n')
- continue
- if 'link rel' in l and '/assets/css/all.css?v=' in l and 'stylesheet' in l:
- fw.write('<link rel="stylesheet" href="/assets/css/all.css?v=1640073543">')
- continue
- if 'link rel' in l and '/assets/css/main.css?v=' in l and 'stylesheet' in l:
- fw.write('<link rel="stylesheet" href="/assets/css/main.css?v=1640073543">')
- continue
- if 'likeSee__state__filter' in l and 'likeSee__state__filter--offset'in l:
- fw.write('<div class="likeSee__state__filter likeSee__state__filter--offset" id="id_offs">')
- continue
- if 'nav-link' in l and '設計師作品' in l and 'class' in l:
- if 'active' in l:
- fw.write('<a href="#" class="nav-link active" onclick="c_intro();" id="a_intro">設計師作品</a>')
- else:
- fw.write('<a href="#" class="nav-link " onclick="c_intro();" id="a_intro">設計師作品</a>')
- continue
- if 'nav-link' in l and '設計師公司簡介' in l and 'class' in l:
- if 'active' in l:
- fw.write('<a href="#" class="nav-link active" onclick="c_comp();" id="a_company">設計師公司簡介</a>')
- else:
- fw.write('<a href="#" class="nav-link " onclick="c_comp();" id="a_company">設計師公司簡介</a>')
- continue
- fw.write(l)
- if '</script>' in l and not scriptflag:
- scriptflag=True
- fw.write('\n <script async defer crossorigin="anonymous" src="https://connect.facebook.net/zh_TW/sdk.js#xfbml=1&version=v9.0" nonce="7TsDzQN7"></script> \n')
- fw.write("\n <script>")
- fw.write("function c_intro(){ \n")
- fw.write("var rintro= document.getElementById('row_intro'); \n")
- fw.write("var rcomp = document.getElementById('row_company'); \n")
- fw.write("var aintro = document.getElementById('a_intro'); \n")
- fw.write("var acompany = document.getElementById('a_company'); \n")
- fw.write("var id_offs = document.getElementById('id_offs'); \n")
- fw.write(' rcomp.style.display = "none"; \n')
- fw.write(' id_offs.style.display="flex"; \n')
- fw.write(' rintro.style.display="flex"; \n')
- # fw.write(' rcomp.style.display = "none"; \n')
- fw.write(' aintro.className = "nav-link active"; \n')
- fw.write(' acompany.className = "nav-link"; \n')
- fw.write("} \n")
- fw.write("function c_comp(){ \n")
- fw.write("var rintro= document.getElementById('row_intro'); \n")
- fw.write("var rcomp = document.getElementById('row_company'); \n")
- fw.write("var aintro = document.getElementById('a_intro'); \n")
- fw.write("var acompany = document.getElementById('a_company'); \n")
- fw.write("var id_offs = document.getElementById('id_offs'); \n")
- fw.write(' id_offs.style.display="none"; \n')
- fw.write(' rintro.style.display="none"; \n')
- fw.write(' rcomp.style.display = "flex"; \n')
- #fw.write(' rintro.style.display="none"; \n')
-
- fw.write(' acompany.className = "nav-link active"; \n')
- fw.write(' aintro.className = "nav-link"; \n')
- fw.write("} </script> \n")
- #
- # print(lines)
- fr.close()
- fw.close()
- db = dataset.connect('mysql://hhh7796hhh:lYmWsu^ujcA1@hhh-v57-cluster.cluster-cmab1ctkglka.ap-northeast-2.rds.amazonaws.com:3306/xoops?charset=utf8mb4')
- dir_prefix='/var/www/jared-six/'
- cursor=db.query('SELECT hdesigner_id FROM xoops._hdesigner where onoff=1; ')
- for c in cursor:
- did=c['hdesigner_id']
- # if did != 23:
- # continue
- print(did)
- curdir=dir_prefix+str(did)
- if not os.path.exists(curdir):
- os.mkdir(curdir)
- os.chdir(curdir)
- os.system('curl https://hhh.com.tw/designers/cases/'+str(did)+'/1-page/new-sort/ -o orig.html')
- # os.system('curl https://hhh.com.tw/designers/index/'+str(did)+'/ -o orig.html')
- os.system('curl https://hhh.com.tw/designers/details/'+str(did)+'/ -o comp.html')
- result=extract_comp(curdir+"/comp.html")
- print(result)
- proc_file(curdir+"/orig.html",curdir+"/index.html",result)
- #for l in lst:
- # os.chdir(curdir)
- # os.system('curl https://hhh.com.tw/columns/detail/'+l+'/ > index.html')
|