zoukankan      html  css  js  c++  java
  • python开发模板(自用 1)

    Main:

    # $ begin
    root_url = "http://hibernate.org/orm/downloads/"
    html_cont = self.downloader.download(root_url)
    new_data = self.parser_$.parse(root_url, html_cont, '')
    self.outputer.collect_data(new_data)
    # $ end

    self.parser_$ = parser_$.HtmlParser()

    import os

    import bs4
    import re
    import urllib.parse
    from bs4 import BeautifulSoup


    class HtmlParser(object):
    def _get_new_data(self, page_url, soup, final_str_name):
    con_datas = []
    res_data = {}
    # url
    res_data['url'] = page_url
    res_data['name'] = '$'

    # print("111111")
    # print(con_data['name'])
    # print("333333")
    # print(con_data['cont'])
    # print("222222")
    return res_data, con_datas

    def save_data(self, new_data, con_datas):
    ret_data = {}

    ret_data['name'] = new_data['name']
    ret_data['url'] = new_data['url']

    flag = 0
    cont = ''
    for data in con_datas:
    # print(data['name'])
    file_name = 'baike\Files\$\' + data['name'] + '.txt'
    # print(file_name)
    file_cont = data['cont']
    # print(data['cont']+'fuck')
    try:
    if (os.path.exists(file_name)):
    # print(file_name)
    pass
    else:
    flag = flag + 1
    cont = cont + ' Update %d: %s %s ' % (flag, data['name'], file_cont)
    fout = open(file_name, 'w', encoding='utf-8')
    fout.write(file_cont)
    fout.close()
    except:
    pass

    if flag == 0:
    cont = cont + 'No Update Information! '

    ret_data['cont'] = cont

    return ret_data
    pass

    def parse(self, page_url, html_cont, final_str_name):
    if page_url is None or html_cont is None:
    return None, None

    soup = BeautifulSoup(html_cont, 'html.parser')
    new_data, con_datas = self._get_new_data(page_url, soup, final_str_name)
    ret_data = self.save_data(new_data, con_datas)
    return ret_data
    pass







    #include<stdio.h>
    #include<math.h>
    #include<iostream>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    typedef unsigned long long  LL ;

    int main(){
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
        char c;
        string fuck = "hibernate";
        cout<<fuck<<endl<<endl;
        while(scanf("%c",&c)!=EOF){
            if(c=='$'){
                cout<<fuck;
            }else{
                cout<<c;
            }
        }
        return 0;
    }

  • 相关阅读:
    安装MeeGo
    一、Android uevent架构
    android键盘映射(转)
    【转】密码学 :CSP的概念
    【原创翻译】链接DLL至可执行文件翻译自MSDN
    【转】c语言中的定义和声明
    Windows:32位程序运行在64位系统上注册表会重定向
    Wow64
    VS2008 ActiveX(ocx控件)的调试工具ActiveX Control Test Container安装说明
    小写bool和大写BOOL的区别
  • 原文地址:https://www.cnblogs.com/clover-xuqi/p/7150442.html
Copyright © 2011-2022 走看看