用Python下载Sharepoint数据列表
2016-08-08 11:24
155 查看
IQY Files to Make Web Query.
OQY file is a Microsoft Excel Web Query. In Microsoft Excel 97, Web queries allow you to query data from a specific World Wide Web, Internet, or intranet site and retrieve the information directly into aMicrosoft Excel worksheet.
In share point, it could export the data list through the query.iqy file. When open the file, it display as bellow, which is the link to download the remote list data.
Download Web Contents in Python
Following are the modules to be imported for downloading. It is majorly based on Requests lib of Python, which is a simple HTTP library encapsulation. import requestsfrom requests_ntlm import HttpNtlmAuth
Session object: allows to persists certain parameters across requests, following is an example to demonstrate how to get url with authentication information.
self.auth_NTLM = HttpNtlmAuth('user name','pass code')
def get_workload_data_from_web(self, url): try: session = requests.Session() return session.get(url, auth=self.auth_NTLM).text except Exception, e: print e return self.get_workload_data_from_web(url)
</pre><pre class="html" name="code"><span style="font-size:12px;"> </span>
Parse List Data as XML
import xml.dom.minidom as DOM from xml.dom.minidom import Document
To use the built-in DOM object in python to parse the XML, following is a simple example.
input_xml_string = """
<root>
<item>
<data version="1.0" url="http://***" />
<data version="2.0" url="http://***" />
</item>
<other>
<data version="1.0" url="http://***" />
<data version="2.0" url="http://***" />
</other>
</root>
"""
import xml.dom.minidom
def get_tagname():
doc = xml.dom.minidom.parseString(input_xml_string)
for node in doc.getElementsByTagName("data"):
print (node, node.tagName, node.getAttribute("version"))
Section 1 - Data table
<span style="font-size:12px;"><s:Schema id='RowsetSchema'> <s:ElementType name='row' content='eltOnly' rs:CommandTimeout='30'> <s:AttributeType <span style="color:#ff6666;">name</span>='ows_Week_x002d_end_x0020_Date' rs:name='Week-end Date' rs:number='1'> <s:datatype dt:type='datetime' dt:maxLength='8' /> </s:AttributeType> <s:AttributeType <span style="color:#ff6666;">name</span>='ows_Tester' rs:name='Tester' rs:number='2'> <s:datatype dt:type='string' dt:lookup='true' dt:maxLength='512' /> </s:AttributeType></span>
Section 2 - Data contents
<span style="font-size:12px;"><rs:data>
<z:row ows_Week_x002d_end_x0020_Date='2016-08-06 00:00:00' ows_Tester='3117;#Wu, You' ows_Requester='6891;#Huang, Huang' ows_CE_x002f_CPL_x0020_work_x003f_='0' ows_Target='N/A' ows_PL='N/A' ows_Type_x0020_of_x0020_Work='Conference' ows_Sub_x002d_Area='N/A' ows_SW_x0020_Info_x002e_='NA' ows_Hardware_x0020_Type='N/A' ows_Hardware_x0020_Version='N/A' ows_Summary='<div class="ExternalClass815F44AAE4A343DB80D951152259A25F"><p>weekly meeting<br></p></div>' ows_Efforts_x0020__x0028_in_x0020_Ho='2.00000000000000' ows_Team_x002d_Leader='Huang He' ows_Created='2016-08-05 17:54:43' ows_ID='660' /></span>
Use the dictionary to store get number by key.
def get_list_of_row_data_xls(self,xml_data,key_list):
list_row_data = []
rows = xml_data.getElementsByTagName('z:row')
for row in rows:
row_data = {}
for key in key_list:
row_data[key] = self.switch_handle_row_data_xls.get(key)(row.getAttribute(key))
list_row_data.append(row_data)
return list_row_data
相关文章推荐
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- python下载google map地图数据
- USACO历年比赛题目列表,测试数据和解题报告下载
- 给InfoPath添加VSTA托管代码并从SharePoint列表查询数据
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- SharePoint 2010 中有个新的列表模板“导入电子表格”可以直接导入Excel数据并创建为列表
- MOSS 2010:Visual Studio 2010开发体验(20)——使用ADO.NET Data Service快速访问SharePoint列表数据
- MOSS 2010:Visual Studio 2010开发体验(20)——使用ADO.NET Data Service快速访问SharePoint列表数据
- [SharePoint 2010 的那些事儿-InfoPath]使用InfoPath表单筛选SharePoint列表数据
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- 在InfoPath 2010中使用SharePoint列表数据连接
- Python中数据结构 列表 元组 字典 序列
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- 在InfoPath中如何添加数据连接到Sharepoint的列表或库
- Sharepoint2010应用开发四:使用客户对象模型(Client Object Model)向SharePoint列表写数据
- sharepoint 2010 列表的数据表视图无法使用 the list cannot be displayed in datasheet view 解决方法