字符串替换 一一映射的有序替换

 

一一映射的有序替换

 

 

 

 

<div class="post_text" id="endText" style="border-top:1px solid #ddd;">
    <p class="otitle">
        (原标题:男子与女友相恋多年 婚前发现她是自己的姨表姑)
    </p>
    <p>相爱多年,夫妻俩竟是失散多年的兄妹,这可能是电视剧里才会出现的桥段。但在最近,就有一位王先生向我们倾诉,自己相爱多年的女朋友,竟然是父亲姨姥的孙女。</p>
    <p class="f_center"><img alt="微信截图_20180415203509.png"
                             src="http://cms-bucket.nosdn.127.net/catchpic/8/85/85a3a6af40548da7e5fdea6543f72e9a.png?imageView&amp;thumbnail=550x0"
                             width="640" height="410"></p>
    <p>王先生今年29岁,几年前他从北京来到南京,遇到了同乡的发小,两人逐渐产生了好感。最近两人打算结婚,可家中老人却发现,双方竟是远房亲戚。</p>
    <p class="f_center"><img alt="微信截图_20180415203539.png"
                             src="http://cms-bucket.nosdn.127.net/catchpic/6/65/659f51e4d83fb3741b513213b6d3dba7.png?imageView&amp;thumbnail=550x0"
                             width="640" height="430"></p>
    <p>谈了多年的女朋友竟然是自家亲戚,王先生不禁惆怅,世界真是太小了。经过律师计算,王先生的女友是他爷爷的姨孙女,也就是王先生的太姨姥的孙女,是属于旁系家族的第四代,而王先生已经属于第五代。</p>
    <p class="f_center"><img alt="微信截图_20180415203523.png"
                             src="http://cms-bucket.nosdn.127.net/catchpic/b/b3/b31c0dc1f9e39d249dec629b6c075122.png?imageView&amp;thumbnail=550x0"
                             width="640" height="454"></p>
    <p><!-- AD200x300_2 -->
    </p>
    <div class="gg200x300">
        <div class="at_item right_ad_item" adtype="rightAd"
             requesturl="https://nex.163.com/q?app=7BE0FC82&amp;c=news&amp;l=133&amp;site=netease&amp;affiliate=news&amp;cat=article&amp;type=logo300x250&amp;location=12">
            <iframe width="300" height="250" frameborder="0" border="0" marginwidth="0" marginheight="0"
                    scrolling="no"></iframe>
        </div>
        <a href="javascript:;" target="_self" class="ad_hover_href"></a>
    </div>
    <p>随后记者来到了南京玄武区民政局婚姻登记处,这里的婚检医生却表示,双方的血缘关系仍有可能对后代造成影响。对此医生建议,他们在婚前应进行严谨专业的婚检。如果发现异常可以及早诊断,这也有利于双方和下一代的健康。</p>
    <p></p>
    <div class="ep-source cDGray">
        <span class="left"><a href="http://news.163.com/"><img
                src="http://img1.cache.netease.com/cnews/css13/img/end_news.png" alt="程钢" width="13" height="12"
                class="icon"></a> 本文来源:看看新闻Knews  </span>
        <!--程钢_NN7377--><span class="ep-editor">责任编辑:程钢_NN7377</span></div>
</div>

 

 

 

<div class="post_text" id="endText" style="border-top:1px solid #ddd;">
    <p class="otitle">
        (原标题:男子与女友相恋多年 婚前发现她是自己的姨表姑)
    </p>
    <p>相爱多年,夫妻俩竟是失散多年的兄妹,这可能是电视剧里才会出现的桥段。但在最近,就有一位王先生向我们倾诉,自己相爱多年的女朋友,竟然是父亲姨姥的孙女。</p>
    <p class="f_center1"><img alt="微信截图_20180415203509.png"
                             src="http://cms-bucket.nosdn.127.net/catchpic/8/85/85a3a6af40548da7e5fdea6543f72e9a.png?imageView&amp;thumbnail=550x0"
                             width="640" height="410"></p>
    <p>王先生今年29岁,几年前他从北京来到南京,遇到了同乡的发小,两人逐渐产生了好感。最近两人打算结婚,可家中老人却发现,双方竟是远房亲戚。</p>
    <p class="f_center2"><img alt="微信截图_20180415203539.png"
                             src="http://cms-bucket.nosdn.127.net/catchpic/6/65/659f51e4d83fb3741b513213b6d3dba7.png?imageView&amp;thumbnail=550x0"
                             width="640" height="430"></p>
    <p>谈了多年的女朋友竟然是自家亲戚,王先生不禁惆怅,世界真是太小了。经过律师计算,王先生的女友是他爷爷的姨孙女,也就是王先生的太姨姥的孙女,是属于旁系家族的第四代,而王先生已经属于第五代。</p>
    <p class="f_center"><img alt="微信截图_20180415203523.png"
                             src="http://cms-bucket.nosdn.127.net/catchpic/b/b3/b31c0dc1f9e39d249dec629b6c075122.png?imageView&amp;thumbnail=550x0"
                             width="640" height="454"></p>
    <p><!-- AD200x300_2 -->
    </p>
    <p>随后记者来到了南京玄武区民政局婚姻登记处,这里的婚检医生却表示,双方的血缘关系仍有可能对后代造成影响。对此医生建议,他们在婚前应进行严谨专业的婚检。如果发现异常可以及早诊断,这也有利于双方和下一代的健康。</p>
    <p></p>
    <div class="ep-source cDGray">
        <span class="left"> 本文来源:看看新闻Knews  </span>
        <!--程钢_NN7377--><span class="ep-editor">责任编辑:程钢_NN7377</span></div>
</div>

 

 

'''
<img onload="editor.fireEvent('contentchange')" src="https://p1.pstatp.com/large/pgc-image/15238623686755f9e3c409a" _src="https://p1.pstatp.com/large/pgc-image/15238623686755f9e3c409a" alt="pgc-image/15238623686755f9e3c409a" buttonadded="true"> 

<img alt="微信截图_20180415203523.png"
                             src="http://cms-bucket.nosdn.127.net/catchpic/b/b3/b31c0dc1f9e39d249dec629b6c075122.png?imageView&thumbnail=550x0"
                             width="640" height="454"><


'''
fhtml, dbhtml_str, pgc_img_url_l = 'toutaio.db.html', '', []
with open(fhtml, 'r', encoding='utf-8') as fr:
    for hi in fr:
        #  hi = hi.replace('"', "'")
        dbhtml_str = '{}{}'.format(dbhtml_str, hi.replace('\n', '').replace('\r', ''))
l = [i ** i * i for i in range(dbhtml_str.count('<img '))]

while '<img ' in dbhtml_str:
        p1 = dbhtml_str.index('<img ')
        tmp = '{}{}'.format(dbhtml_str[0:p1].replace('>', 'X'), dbhtml_str[p1:])
        p2 = tmp.index('>')
        dbhtml_str = '{}{}{}'.format(dbhtml_str[0:p1], l[0], dbhtml_str[p2+1:])
        del l[0]

  

        js = 'window.location.href="https://mp.toutiao.com/profile_v3/graphic/resource-manager";'
        browser.execute_script(js)
        time.sleep(2)
        xp = '//*[@id="graphic"]/div/div/div[3]/div/div[1]/div[3]/div/input'
        upload = browser.find_element_by_xpath(xp)
        for img_url in pgc_img_url_l:
            local_img_path = spider_webimg_dl_return_local_img_path(img_dir, img_url)
            upload.send_keys(local_img_path)

        time.sleep(10 * len(pgc_img_url_l))
        pgc_img_url_l_toutiao = [i.find_element_by_tag_name('img').get_attribute('src') for i in
                                 browser.find_elements_by_class_name('pic')][0:len(pgc_img_url_l)]
        pgc_img_url_l_toutiao = [i for i in sorted(pgc_img_url_l_toutiao, reverse=True)]

        '''
       <img onload="editor.fireEvent('contentchange')" src="https://p1.pstatp.com/large/pgc-image/15238623686755f9e3c409a" _src="https://p1.pstatp.com/large/pgc-image/15238623686755f9e3c409a" alt="pgc-image/15238623686755f9e3c409a" buttonadded="true"> 
       '''
        dbhtml_str_ = dbhtml_str
        img_n = dbhtml_str_.count('<img')
        s = '<img onload="editor.fireEvent(\'contentchange\')" src="https://p1.pstatp.com/large/pgc-image/TTimgCode" _src="https://p1.pstatp.com/large/pgc-image/TTimgCode" alt="pgc-image/TTimgCode" buttonadded="true">'
        s = '<img onload="editor.fireEvent(\'contentchange\')" src="https://p1.pstatp.com/large/pgc-image/TTimgCode" _src="https://p1.pstatp.com/large/pgc-image/TTimgCode" alt="pgc-image/TTimgCode" buttonadded="true">'
        s = "<img onload='editor.fireEvent(\'contentchange\')' src='https://p1.pstatp.com/large/pgc-image/TTimgCode' _src='https://p1.pstatp.com/large/pgc-image/TTimgCode' alt='pgc-image/TTimgCode' buttonadded='true'>"
        ss = ''
        l = pgc_img_url_l_toutiao
        for i in range(img_n):
            if i == 0:
                p1 = dbhtml_str.index('<img ',0)
            else:
                p1 =dbhtml_str.index('<img ',p1+3)

            tmp = '{}{}'.format(dbhtml_str[0:p1].replace('>', 'X'), dbhtml_str[p1:])
            p2 = tmp.index('>')
            ss = s.replace('TTimgCode', l[0].split('/')[-1])
            dbhtml_str = '{}{}{}'.format(dbhtml_str[0:p1], ss, dbhtml_str[p2 + 1:])
            del l[0]
  

 

posted @ 2018-04-16 15:46  papering  阅读(336)  评论(0编辑  收藏  举报