- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
对于此处包含的数据:http://www.playonline.com/ff11us/polnews/news.xml
我有这段 Python 代码:
import xml.etree.ElementTree as ET
import urllib.request
rss1 = "http://www.playonline.com/ff11us/polnews/news.xml"
f = urllib.request.urlopen(rss1)
objects = ET.fromstring(f.read().decode())
print([el.attrib.get('title') for el in objects.findall('*/item')])
但它返回一个空白数组。我选错树了吗?我需要选择一棵子树或类似的东西吗?
试图掌握布局:
>>> for o in objects:
... print(o.tag)
...
{http://purl.org/rss/1.0/}channel
{http://purl.org/rss/1.0/}item
{http://purl.org/rss/1.0/}item
{http://purl.org/rss/1.0/}item
{http://purl.org/rss/1.0/}item
{http://purl.org/rss/1.0/}item
所以选择 item
我认为可行,还是我需要选择整行?
我可以选择 ./{http://purl.org/rss/1.0/}item
来获取父项,但我如何获取数据(链接
) 来自子项目?
最佳答案
我认为您的原始代码没有任何问题,只是它需要使用 namespace (以完全限定元素)。我将 namespace 的哈希添加到您的代码中。看看它是否适合您。
import xml.etree.ElementTree as etree
import urllib.request
pon_url = "http://www.playonline.com/ff11us/polnews/news.xml"
response = urllib.request.urlopen(pon_url)
xmlstr = response.read().decode()
root = etree.fromstring(xmlstr)
/* This is the namespaces. We use it later during 'findall' */
ns = {'ns1':'http://purl.org/rss/1.0/','ns2':'http://purl.org/dc/elements/1.1/'}
#etree.dump(root)
print("\nItems:\n")
print([i.text for i in root.findall('./ns1:item/ns1:title',ns)])
print("\nlinks:\n")
print([i.text for i in root.findall('./ns1:item/ns1:link',ns)])
print("\nDescriptions:\n")
print([i.text for i in root.findall('./ns1:item/ns1:description',ns)])
print("\nDates\n");
print([i.text for i in root.findall('./ns1:item/ns2:date',ns)])
结果:
Items:
['FINAL FANTASY XI Updated (Nov. 9)', 'All Worlds Maintenance (Nov. 9)', 'Temporary Suspension of NA GM Petition Service (Nov. 5)', 'Recovery from Fenrir World Technical Difficulties (Oct. 29)', 'Fenrir World Several Areas Technical Difficulties (Oct. 29)']
links:
['http://www.playonline.com/ff11us/polnews/news24770.shtml', 'http://www.playonline.com/ff11us/polnews/news24767.shtml', 'http://www.playonline.com/ff11us/polnews/news24765.shtml', 'http://www.playonline.com/ff11us/polnews/news24762.shtml', 'http://www.playonline.com/ff11us/polnews/news24759.shtml']
Descriptions:
['A version update was performed on FINAL FANTASY XI at the following time.<br><br>* Clients will update automatically upon launch after the date and time below. After the following time, the update will automatically begin after you press the "Play" button. After that, please follow the instructions on the screen.<br><br>[Date & Time]<br>Nov. 9, 2016 21:00 (PST)<br><br>[Affected Service]<br>FINAL FANTASY XI<br><br>[Update Details]<br><a href="http://sqex.to/DYa" target="_blank">http://sqex.to/DYa</a>', 'At the following time, we will be performing server maintenance. During this period, FINAL FANTASY XI will be unavailable.<br><br>We apologize for any inconvenience this may cause and thank you for your patience.<br><br>* This maintenance will be accompanied by a client program version update. After maintenance is complete, the update will automatically begin after you press the "Play" button. After that, please follow the instructions on the screen.<br><br>* The World Transfer Service will be unavailable starting 30 minutes before the maintenance.<br><br>*After the maintenance ends, a spike in access is expected.<br>If you encounter congestion errors such as "POL-1160" and "POL-0010" during the confirmation screen or while downloading, we apologize for the inconvenience, and we ask that you try again after waiting for some time.<br><br>To ensure a smooth version update, we ask for your understanding and cooperation.<br><br>*Update details will be announced on Nov. 9, 2016 (PST)<br><br>[Date & Time]<br>Nov. 9, 2016 21:00 to 23:00 (PST)<br>* Completion time is subject to change.<br><br>[Affected Service]<br>- FINAL FANTASY XI', 'At the following time, the North American GM petition service will be temporarily unavailable.<br><br>The European GM petition service will be operating normally and users may still place GM calls for urgent issues. However, please be aware that there may be significant delays until these GM calls can be answered.<br><br>We apologize for the inconvenience and thank you for your patience in this matter.<br><br>[Date & Time]<br>Nov. 5, 2016 1:00 to 4:00 (PDT)<br><br>[Affected Services]<br>- The North American GM Petition service for FINAL FANTASY XI<br><br>[Cause]<br>Building Maintenance', 'At the time below, players were unable to access several areas on the Fenrir World.<br><br>We are pleased to announce that the issue has been addressed. We apologize for any inconvenience this may have caused.<br><br>[Date & Time]<br>Oct. 29, 2016 from 2:58 to 4:32 (PDT)<br><br>[Details]<br>- Unable to access certain areas on the Fenrir World<br><br>[Cause]<br>- Server equipment issue<br><br>[Affected Areas]<br>Unable to access the following areas:<br>- Newton Movalpolos<br>- Abyssea - Konschtat<br>- Lufaise Meadows<br>- Monarch Linn<br>- The Garden of Ru'Hmet<br>- Dynamis - Tavnazia<br>- Aydeewa Subterrane<br>- La Vaule [S]<br>- West Ronfaure<br>- North Gustaberg<br>- South Gustaberg<br>- Cape Teriggan<br>- East Sarutabaruta<br>- Ru'Aun Gardens<br>- Fort Ghelsba<br>- Qulun Dome<br>- Castle Oztroja<br>- Castle Zvahl Keep [S]<br>- Sacrificial Chamber<br>- Throne Room<br>- Ranguemont Pass<br>- Ve'Lugannon Palace<br>- Dynamis - Windurst<br>- Dangruf Wadi<br>- Outer Horutoto Ruins<br>- Ifrit's Cauldron<br>- Qu'Bia Arena<br>- Cloister of Tremors<br>- Abyssea - Attohwa<br>- Ship bound for Selbina<br>- Jeuno-Windurst Airship<br>- Northern San d'Oria<br>- Windurst Waters<br>- Lower Jeuno', 'We are currently experiencing technical difficulties with certain areas on the Fenrir World. The issue is currently under investigation, and new updates will follow as additional information becomes available.<br><br>We apologize for any inconvenience this may be causing, and we thank you for your understanding.<br><br>[Date & Time]<br>From Oct. 29, 2016 2:58 (PDT)<br><br>[Affected]<br>- Certain areas on the Fenrir World<br><br>[Cause]<br>Under investigation<br><br>[Details]<br>Under investigation']
Dates
['Thu, 10 Nov 2016 15:06:13 JST', 'Mon, 07 Nov 2016 14:14:32 JST', 'Fri, 04 Nov 2016 17:18:30 JST', 'Sat, 29 Oct 2016 20:05:44 JST', 'Sat, 29 Oct 2016 20:05:44 JST']
关于python-3.x - 元素树 : selecting right tree?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40567366/
我有一个 Segment 类和一个这样的段数组: private static class Segment { int number, type; Segment(in
我在 SO 中看到一些创建 multilanguage websites in JavaScript 的好建议包括 this article on JavaScript internationaliz
我们有浏览器前缀或黑客 (for Google and Safari) text-align: -webkit-right; (for Firefox) text-align:
过去几天我一直在关注这个问题,我正处于需要寻求帮助的地步。 http://cub.northnodes.com/index.php/about/mission/ 我需要立即捐赠 列一直 float 到
When I press right ctrl, I want the right shift the text will align right. When I press left ctrl le
我已经将右侧的列拆分为顶部和底部。在每个部分中,我在执行以下操作时遇到问题:我希望顶部占据左列高度的 50%,底部占据左列高度的另外 50%。 +-------------------+-------
我知道这个问题的标题很糟糕。对不起。 我有四个 div similar to this .我想要做的只是让 div 编号 2 和 4 之间的垂直空间被删除,而不改变 HTML 的结构。是否可以仅使用
我将表格设置为 100% 宽度。我会添加一个带有 php 的随机 div,有时会充满广告。我希望广告 div 位于表格的右侧和内容。我希望表格位于左侧,但仍为 100% 左右,它将填充广告 div 左
这个问题在这里已经有了答案: Bootstrap align navbar items to the right (24 个答案) 关闭 5 年前。
.floatright { float: right;margin: 0 0 10px 10px;clear: right;width:60px; height:60px; } Lorem
我正在尝试将 td 中的某些内容右对齐。 align="right"有效,但 text-align:right 无效。这是一个 jsfiddle显示这两种情况的示例。除了右对齐右列外,这两种情况是相同
在设计网站时,您认为用于特定任务的最佳图像格式是什么? 在试图找出用于特定任务的格式时,我总是发现自己处于两难境地……例如,我应该全面使用 .jpg 吗?或者,我何时以及为什么应该使用 .png? 例
我是一个 MySQL 新手,今天我尝试设置一个超过 5 行的 MySQL 调用。我不断收到语法错误,我尝试修复了几个小时,但我不知道问题出在哪里。这是代码: USE myDatabase; DELIM
这让我发疯。我有一个 div float 到另一个 div 的右侧,如下所示: Current Membership: 我有以下 css 规则: div#container { f
我有以下代码片段,它会产生不需要的“填充”区域,而填充为零。如何避免这个区域? 代码 div.left { background-color: red; max-width: 25%; f
在 C++ 中,表达式 left() = right() 求值 right() left() 按那个顺序。 right() 先行,正如已讨论过的 here. 我想不出让 right() 先走的理由。你
我有一个很小的菜单列表,当鼠标靠近时它应该会增长。在其原始状态下,菜单是右对齐的,悬停时每第二个元素向右移动并左对齐以为增加的高度腾出空间(参见 JSFiddle )。 ul { font-siz
td.myclass{ width: 6em; text-align: right; padding-right: 2em; } 如您所见,我希望单元格中的文本右对齐,距离单元
你怎么能看到 http://jsfiddle.net/73wst/ 我想在停止下开始,但我不知道如何设置它的样式。 我的 HTML: Stop Start 我的 CSS: .sta
一个大的内部 div 在一个小的外部 div 中,并且外部 div 溢出自动。但是为什么没有内部 div margin-right 和外部 div padding-right? html
我是一名优秀的程序员,十分优秀!