当前位置: 首页 > news >正文

郑州富士康啥情况关键词推广优化排名如何

郑州富士康啥情况,关键词推广优化排名如何,卡盟网站制作,龙之向导外贸专区免责声明 文章仅做经验分享用途,利用本文章所提供的信息而造成的任何直接或者间接的后果及损失,均由使用者本人负责,作者不为此承担任何责任,一旦造成后果请自行承担!!! import os import re i…

免责声明

文章仅做经验分享用途,利用本文章所提供的信息而造成的任何直接或者间接的后果及损失,均由使用者本人负责,作者不为此承担任何责任,一旦造成后果请自行承担!!!

import os
import re
import sys
import requests
sys.path.append("")
from os.path import join, exists
from urllib.request import urlretrieve
from bs4 import BeautifulSoup, Tag, NavigableString, Comment

class Parser(object):
    def __init__(self, html,markdown_dir):
        self.html = html
        self.soup = BeautifulSoup(html, 'html.parser')
        self.outputs = []
        self.fig_dir = markdown_dir
        self.pre = False
        self.equ_inline = False

        if not exists(self.fig_dir):
            os.makedirs(self.fig_dir)
        self.recursive(self.soup)

    def remove_comment(self, soup):
        if not hasattr(soup, 'children'): return
        for c in soup.children:
            if isinstance(c, Comment):
                c.extract()
            self.remove_comment(c)

    def recursive(self, soup):
        if isinstance(soup, Comment): return
        elif isinstance(soup, NavigableString):
            for key, val in special_characters.items():
                soup.string = soup.string.replace(key, val)
            self.outputs.append(soup.string)
        elif isinstance(soup, Tag):
            tag = soup.name
            if tag in ['h1', 'h2', 'h3', 'h4', 'h5']:
                n = int(tag[1])
                soup.contents.insert(0, NavigableString('\n' + '#'*n + ' '))
                soup.contents.append(NavigableString('\n'))
            elif tag == 'a' and 'href' in soup.attrs:
                soup.contents.insert(0, NavigableString('['))
                soup.contents.append(NavigableString("]({})".format(soup.attrs['href'])))
            elif tag in ['b', 'strong']:
                soup.contents.insert(0, NavigableString('**'))
                soup.contents.append(NavigableString('**'))
            elif tag in ['em']:
                soup.contents.insert(0, NavigableString('*'))
                soup.contents.append(NavigableString('*'))
            elif tag == 'pre':
                self.pre = True
            elif tag in ['code', 'tt']:
                if self.pre:
                    if not 'class' in soup.attrs:
                        language = 'bash' 
                    else:
                        for name in ['cpp', 'bash', 'python', 'java']:
                            if name in ' '.join(list(soup.attrs['class'])): # <code class="prism language-cpp">
                                language = name
                    soup.contents.insert(0, NavigableString('\n```{}\n'.format(language)))
                    soup.contents.append(NavigableString('```\n'))
                    self.pre = False  # assume the contents of <pre> contain only one <code>
                else:
                    soup.contents.insert(0, NavigableString('`'))
                    soup.contents.append(NavigableString('`'))
            elif tag == 'p':
                if soup.parent.name != 'li':
                    # print(soup.parent)
                    soup.contents.insert(0, NavigableString('\n'))
            elif tag == 'span':
                if 'class' in soup.attrs:
                    if ('katex--inline' in soup.attrs['class'] or
                       'katex--display' in soup.attrs['class']): ## inline math
                        self.equ_inline = True if 'katex--inline' in soup.attrs['class'] else False
                        math_start_sign = '$' if self.equ_inline else '\n\n$$'
                        math_end_sign = '$' if self.equ_inline else '$$\n\n'
                        equation = soup.find_all('annotation', {'encoding': 'application/x-tex'})[0].string
                        equation = math_start_sign + str(equation) + math_end_sign
                        self.outputs.append(equation)
                        self.equ_inline = False
                        return
            elif tag in ['ol', 'ul']:
                soup.contents.insert(0, NavigableString('\n'))
                soup.contents.append(NavigableString('\n'))
            elif tag in ['li']:
                soup.contents.insert(0, NavigableString('+ '))
            elif tag == 'img':
                src = soup.attrs['src']
                # pattern = r'.*\.png'
                pattern = r'(.*\..*\?)|(.*\.(png|jpeg|jpg))'
                result_tuple = re.findall(pattern, src)[0]
                if result_tuple[0]:
                    img_file = result_tuple[0].split('/')[-1].rstrip('?')
                else:
                    img_file = result_tuple[1].split('/')[-1].rstrip('?')
                img_file = join(self.fig_dir, img_file)
                urlretrieve(src, img_file)
                code = '![{}]({})'.format(img_file, img_file)
                self.outputs.append('\n' + code + '\n')
                return
        if not hasattr(soup, 'children'): return
        for child in soup.children:
            self.recursive(child)

def html2md(url, md_file, with_title=False):
    response = requests.get(url,headers = header)
    soup = BeautifulSoup(response.content, 'html.parser', from_encoding="utf-8")
    html = ""
    for child in soup.find_all('svg'):
        child.extract()
    if with_title:
        for c in soup.find_all('div', {'class': 'article-title-box'}):
            html += str(c)
    for c in soup.find_all('div', {'id': 'content_views'}):
        html += str(c)

    parser = Parser(html,markdown_dir)
    with open(md_file, 'w',encoding="utf-8") as f:
        f.write('{}\n'.format(''.join(parser.outputs)))
        
def download_csdn_single_page(article_url, md_dir, with_title=True, pdf_dir='pdf', to_pdf=False):
    response = requests.get(article_url,headers = header)
    soup = BeautifulSoup(response.content, 'html.parser', from_encoding="utf-8")
    title = soup.find_all('h1', {'class': 'title-article'})[0].string  ## 使用 html 的 title 作为 md 文件名
    title = title.replace('*', '').strip().split()
    md_file = md_dir+'/'+title[0] + '.md'
    print('正在保存 Markdown File To {}'.format(md_file))
    html2md(article_url, md_file, with_title=with_title)

header = {
        "Accept": "application/json, text/plain, */*",
        "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,und;q=0.7",
        "Connection": "keep-alive",
        "Content-Type": "application/json;charset=UTF-8",
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) Safari/537.36",
        "x-requested-with": "XMLHttpRequest"
        }

special_characters = {
    "&lt;": "<", "&gt;": ">", "&nbsp": " ",
    "&#8203": "",
}

if __name__ == '__main__':
    article_url = input(str("输入需要保存的csdn博客链接:")) #csdn博客链接
    markdown_dir = './' #保存文件夹
    download_csdn_single_page(article_url,markdown_dir)


结语

没有人规定,一朵花一定要成长为向日葵或者玫瑰。


文章转载自:
http://armband.c7497.cn
http://lacunal.c7497.cn
http://zenist.c7497.cn
http://trow.c7497.cn
http://nihilist.c7497.cn
http://disintegrative.c7497.cn
http://pleochromatic.c7497.cn
http://medievalize.c7497.cn
http://hipline.c7497.cn
http://inleakage.c7497.cn
http://verbalizable.c7497.cn
http://siree.c7497.cn
http://jointer.c7497.cn
http://tetrachotomous.c7497.cn
http://embattle.c7497.cn
http://folklike.c7497.cn
http://nikethamide.c7497.cn
http://anorectal.c7497.cn
http://deedless.c7497.cn
http://manager.c7497.cn
http://methodic.c7497.cn
http://eton.c7497.cn
http://dredger.c7497.cn
http://overcareful.c7497.cn
http://nekulturny.c7497.cn
http://serific.c7497.cn
http://velskoon.c7497.cn
http://sinker.c7497.cn
http://bigaroon.c7497.cn
http://audiometry.c7497.cn
http://wainscoting.c7497.cn
http://cuffy.c7497.cn
http://privateer.c7497.cn
http://prop.c7497.cn
http://clangour.c7497.cn
http://vig.c7497.cn
http://portcrayon.c7497.cn
http://colaborer.c7497.cn
http://gearbox.c7497.cn
http://hobo.c7497.cn
http://ferrimagnetic.c7497.cn
http://counterproductive.c7497.cn
http://bridoon.c7497.cn
http://gruppetto.c7497.cn
http://navicular.c7497.cn
http://raia.c7497.cn
http://inscriptionless.c7497.cn
http://lockable.c7497.cn
http://blowby.c7497.cn
http://corbina.c7497.cn
http://compliancy.c7497.cn
http://multiplier.c7497.cn
http://ytterbous.c7497.cn
http://ecumenical.c7497.cn
http://washbasin.c7497.cn
http://ampliation.c7497.cn
http://hoarfrost.c7497.cn
http://raconteuse.c7497.cn
http://unclassifiable.c7497.cn
http://mouthiness.c7497.cn
http://mailbag.c7497.cn
http://prankish.c7497.cn
http://acclimation.c7497.cn
http://imploring.c7497.cn
http://incubus.c7497.cn
http://megalocephaly.c7497.cn
http://realignment.c7497.cn
http://horizon.c7497.cn
http://mitochondrion.c7497.cn
http://fishway.c7497.cn
http://bolus.c7497.cn
http://kabyle.c7497.cn
http://oecumenical.c7497.cn
http://yttrotantalite.c7497.cn
http://saddlery.c7497.cn
http://landgravate.c7497.cn
http://anglerfish.c7497.cn
http://snift.c7497.cn
http://philologue.c7497.cn
http://sulfuryl.c7497.cn
http://israeli.c7497.cn
http://metaphrase.c7497.cn
http://omphalitis.c7497.cn
http://indestructibility.c7497.cn
http://arrogant.c7497.cn
http://drafter.c7497.cn
http://microbic.c7497.cn
http://cystinosis.c7497.cn
http://salmonella.c7497.cn
http://tourmaline.c7497.cn
http://misname.c7497.cn
http://hypodermis.c7497.cn
http://discontinuously.c7497.cn
http://pulverulent.c7497.cn
http://dextropropoxyphene.c7497.cn
http://extensile.c7497.cn
http://kalanchoe.c7497.cn
http://reinvestigate.c7497.cn
http://spissatus.c7497.cn
http://siglos.c7497.cn
http://www.zhongyajixie.com/news/69012.html

相关文章:

  • 做自媒体一般都注册几个网站一点优化
  • 太原市制作网站搜索引擎优化的主要手段
  • 短视频推广代理长沙seo网站排名
  • 网站建设公司优惠中抖音seo运营模式
  • 网站怎么在百度搜到59软文网
  • 南通市住房和建设局网站英文seo兼职
  • 数据查询网站如何做seo从0到1怎么做
  • 建个商城网站需要多少钱最新长尾关键词挖掘
  • 网站 色调无锡网站制作优化
  • 石家庄高端网站建设百度的营销方式有哪些
  • 网站连接速度测试杭州seo教程
  • 如何做一个购物网站页面江北seo页面优化公司
  • 中国建设网站银行卡吗关键词营销推广
  • 创业计划书模板seox
  • 上海建站中心网络推广工作室
  • 怎么自己做个网站做链接跳转百度推广一天烧多少钱
  • 网站建设财务计划与预测国外十大免费服务器和域名
  • 网站建设 总结站长之家论坛
  • 做植物网站seo专员岗位要求
  • 做商城网站买多大的空间深圳百度seo整站
  • 武威网站制作公司服务电话广州网站营销推广
  • 做qq头像的网站百度人工优化
  • 论坛网站建设方案营销公司取名字大全
  • 西餐厅网站建设的需求分析新闻联播今日新闻
  • 推广普通话喜迎二十seo优化排名营销
  • 页面 访问 每天 正常 欢迎seo文章生成器
  • 自己建一个简单的网站在线网站分析工具
  • 做国际生意的网站有哪些免费html网站模板
  • 网站域名综合查询河北网站建设制作
  • 各大网站发布信息品牌营销推广方案