首页 文章 精选 留言 我的

精选列表

搜索[Python],共10000篇文章
优秀的个人博客,低调大师

python的xml.dom学习笔记

首先说一下,由于这篇文章主要是自己随性学习写的,所以读者看起来可能很乱,呵呵。可以给大家稍微推荐一篇:http://www.cnblogs.com/xuxm2007/archive/2011/01/16/1936610.html稍微清晰一点 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 #coding=utf-8 #解析xml文件中的所有的link标签 from xml.dom import minidom from xml.dom.minidom import getDOMImplementation doc = minidom.parse( "d:\\hello.html" ) nodes = doc.getElementsByTagName( "link" ) for node in nodes: print "<" ,node.tagName, print "type=\"" ,node.getAttribute( "type" ), "\"" , print "rel=\"" ,node.getAttribute( "rel" ), "\"" , print "href=\"" ,node.getAttribute( "href" ), "\"" , print "/>" print "通过另外一种方式获得link标签" linknodes = doc.getElementsByTagName( "link" ) for i in range ( len (linknodes)): print linknodes[i].getAttribute( "type" ), print linknodes[i].getAttribute( "rel" ), print linknodes[i].getAttribute( "href" ) #操作节点 node = linknodes[ 0 ] print dir (node) print node.parentNode print node.prefix print node.nodeType,node.nodeValue,node.nodeName print node.localName print node.childNodes print node.firstChild,node.lastChild print node.attributes print node.namespaceURI print node.nextSibling print "--" * 10 print node.tagName print "===" * 20 impl = getDOMImplementation() newdoc = impl.createDocument( None , "some_tag" , None ) top_element = newdoc.documentElement node1 = newdoc.createTextNode( "node1" ) node2 = newdoc.createTextNode( "node2" ) node3 = newdoc.createTextNode( "node3" ) top_element.appendChild(node1) top_element.appendChild(node2) top_element.appendChild(node3) top_element.removeChild(node3) top_element.insertBefore(node3,node2) print top_element.childNodes 运行结果: < link type = " text/css " rel = " stylesheet " href = " http://www.cnblogs.com/css/common.css " / > < link type = " text/css " rel = " stylesheet " href = " http://www.cnblogs.com/Skins/kubrick/style.css " / > < link type = " text/css " rel = " stylesheet " href = " http://www.cnblogs.com/css/common2.css " / > < link type = " text/css " rel = " stylesheet " href = " http://common.cnblogs.com/css/shCore.css " / > < link type = " text/css " rel = " stylesheet " href = " http://common.cnblogs.com/css/shThemeDefault.css " / > < link type = " application/rss+xml " rel = " alternate " href = " http://www.cnblogs.com/rollenholt/rss " / > < link type = " application/rsd+xml " rel = " EditURI " href = " http://www.cnblogs.com/rollenholt/rsd.xml " / > < link type = " application/wlwmanifest+xml " rel = " wlwmanifest " href = " http://www.cnblogs.com/rollenholt/wlwmanifest.xml " / > 通过另外一种方式获得link标签 text / css stylesheet http: / / www.cnblogs.com / css / common.css text / css stylesheet http: / / www.cnblogs.com / Skins / kubrick / style.css text / css stylesheet http: / / www.cnblogs.com / css / common2.css text / css stylesheet http: / / common.cnblogs.com / css / shCore.css text / css stylesheet http: / / common.cnblogs.com / css / shThemeDefault.css application / rss + xml alternate http: / / www.cnblogs.com / rollenholt / rss application / rsd + xml EditURI http: / / www.cnblogs.com / rollenholt / rsd.xml application / wlwmanifest + xml wlwmanifest http: / / www.cnblogs.com / rollenholt / wlwmanifest.xml [ 'ATTRIBUTE_NODE' , 'CDATA_SECTION_NODE' , 'COMMENT_NODE' , 'DOCUMENT_FRAGMENT_NODE' , 'DOCUMENT_NODE' , 'DOCUMENT_TYPE_NODE' , 'ELEMENT_NODE' , 'ENTITY_NODE' , 'ENTITY_REFERENCE_NODE' , 'NOTATION_NODE' , 'PROCESSING_INSTRUCTION_NODE' , 'TEXT_NODE' , '__doc__' , '__init__' , '__module__' , '__nonzero__' , '__repr__' , '_attrs' , '_attrsNS' , '_call_user_data_handler' , '_child_node_types' , '_get_attributes' , '_get_childNodes' , '_get_firstChild' , '_get_lastChild' , '_get_localName' , '_get_tagName' , '_magic_id_nodes' , 'appendChild' , 'attributes' , 'childNodes' , 'cloneNode' , 'firstChild' , 'getAttribute' , 'getAttributeNS' , 'getAttributeNode' , 'getAttributeNodeNS' , 'getElementsByTagName' , 'getElementsByTagNameNS' , 'getInterface' , 'getUserData' , 'hasAttribute' , 'hasAttributeNS' , 'hasAttributes' , 'hasChildNodes' , 'insertBefore' , 'isSameNode' , 'isSupported' , 'lastChild' , 'localName' , 'namespaceURI' , 'nextSibling' , 'nodeName' , 'nodeType' , 'nodeValue' , 'normalize' , 'ownerDocument' , 'parentNode' , 'prefix' , 'previousSibling' , 'removeAttribute' , 'removeAttributeNS' , 'removeAttributeNode' , 'removeAttributeNodeNS' , 'removeChild' , 'replaceChild' , 'schemaType' , 'setAttribute' , 'setAttributeNS' , 'setAttributeNode' , 'setAttributeNodeNS' , 'setIdAttribute' , 'setIdAttributeNS' , 'setIdAttributeNode' , 'setUserData' , 'tagName' , 'toprettyxml' , 'toxml' , 'unlink' , 'writexml' ] <DOM Element: head at 0x1b3e968 > None 1 None link link [] None None <xml.dom.minidom.NamedNodeMap object at 0x01B4D648 > http: / / www.w3.org / 1999 / xhtml <DOM Text node "u'\n'" > - - - - - - - - - - - - - - - - - - - - link = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = [<DOM Text node "'node1'" >, <DOM Text node "'node3'" >, <DOM Text node "'node2'" >] ============================================================================== 本文转自被遗忘的博客园博客,原文链接:http://www.cnblogs.com/rollenholt/archive/2011/12/01/2271131.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

python 获取yahoo股票数据

1 2 3 4 5 6 7 8 9 import pandasaspd from pandas_datareader import data import datetime start = datetime.datetime( 2016 , 1 , 1 ) end = datetime.date.today() apple = data.DataReader( "AAPL" , "yahoo" ,start,end) #type(apple) apple.head() Date Open High Low Close Adj Close Volume 2016-01-04 102.610001 105.370003 102.000000 105.349998 101.790649 67649400 2016-01-05 105.750000 105.849998 102.410004 102.709999 99.23984555791000 2016-01-06 100.559998 102.370003 99.870003 100.699997 97.29776068457400 2016-01-07 98.680000 100.129997 96.430000 96.449997 93.19133881094400 2016-01-08 98.550003 99.110001 96.760002 96.959999 93.68412070798000 本文转自 326647452 51CTO博客,原文链接:http://blog.51cto.com/svsky/1956586,如需转载请自行联系原作者

优秀的个人博客,低调大师

[Spark][Python]Mapping Single Rows to Multiple Pairs

Mapping Single Rows to Multiple Pairs 目的: 把如下的这种数据, Input Data 00001 sku010:sku933:sku022 00002 sku912:sku331 00003 sku888:sku022:sku010:sku594 00004 sku411 转换为这样: 一个Key值,带的这几个键值,分别罗列: (00001,sk010) (00001,sku933) (00001,sku022) ... (00002,sku912) (00002,sku331) (00003,sku888) 这就是所谓的 Mapping Single Rows to Multiple Pairs 步骤如下: [training@localhost ~]$ vim act001.txt [training@localhost ~]$ [training@localhost ~]$ cat act001.txt 00001 ku010:sku933:sku022 00002 sku912:sku331 00003 sku888:sku022:sku010:sku594 00004 sku411 [training@localhost ~]$ hdfs dfs -put act001.txt [training@localhost ~]$ [training@localhost ~]$ hdfs dfs -cat act001.txt 00001 ku010:sku933:sku022 00002 sku912:sku331 00003 sku888:sku022:sku010:sku594 00004 sku411 [training@localhost ~]$ In [6]: mydata01=mydata.map(lambda line: line.split("\t")) In [7]: type(mydata01) Out[7]: pyspark.rdd.PipelinedRDD In [8]: mydata02=mydata01.map(lambda fields: (fields[0],fields[1])) In [9]: type(mydata02) Out[9]: pyspark.rdd.PipelinedRDD In [10]: In [11]: mydata03 = mydata02.flatMapValues(lambda skus: skus.split(":")) In [12]: type(mydata03) Out[12]: pyspark.rdd.PipelinedRDD In [13]: mydata03.take(1) Out[13]: [(u'00001', u'ku010')] 本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/p/7603900.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

python操作文件写入内容

1 2 3 4 5 6 7 8 9 10 11 12 13 14 [root@bogon~] #catfile.py #/usr/bin/envpython #coding:utf-8 ecs = "efwefwffrfrer" ipaddrr = "192.168.56.10" print type (ecs + "" + ipaddrr + "hasstopeed" ) def write_result( str ): writeresult = file (r '/tmp/ecs.log' , 'a+' ) str1 = writeresult.write( str + '\n' ) writeresult.close() return str if __name__ = = "__main__" : write_result(ecs + "" + ipaddrr + "hasstopeed" ) [root@bogon~] # 本文转自 小小三郎1 51CTO博客,原文链接:http://blog.51cto.com/wsxxsl/2068670,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册