- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
虽然使用 pageobject gem 能够获取表的标题和行,但无法使用以下代码将其转换为散列,但我只能将第一行映射到标题,但我需要映射完整的表行到标题。
如何使用 nokogiri 来做到这一点,因为表很大并且需要很长时间才能加载
这是表格数据的链接:https://www.w3schools.com/html/html_tables.asp
我试过下面的代码:
class WbPage
include PageObject
page_url 'https://www.w3schools.com/html/html_tables.asp'
table(:customers, id: 'customers')
def get_table_data
headers = customers_element.ths.collect { |th| th.inner_html }
rows = customers_element.tds.collect { |td| td.inner_html }
data = {}
headers.zip(rows) { |header,row| data[header.to_sym] = row }
puts data
end
end
我得到上面代码的以下输出:
{:Company=>"Alfreds Futterkiste", :Contact=>"Maria Anders", :Country=>"Germany"}
但我需要这样:
{:Company => "Alfreds Futterkiste", "Centro comercial Moctezuma", "Ernst Handel", "Island Trading", "Laughing Bacchus Winecellars", "Giovanni Rovelli"
:Contact => "Maria Anders", "Francisco Chang", "Roland Mendel", "Helen Bennett", "Yoshi Tannamuri", "Magazzini Alimentari Riuniti"
:Contry => "Germany", "Mexico", "Austria", "UK", "Canada", "Italy"}
如果我有这样的表怎么办
--------------------------------------------------
Location | Time | Miles <-- First tr with headers (I need to ignore it)
--------------------------------------------------
Fuel | Inspection | State | Zone | ETA | ETD | <-- Second tr with headers (from here i need the data)
--------------------------------------------------
F | I | Omaha | Nebraska | 27 08:00 | 27 08:30 |
F | I | Omaha | Nebraska | 27 08:00 | 27 08:30 |
F | I | Omaha | Nebraska | 27 08:00 | 27 08:30 |
F | I | Omaha | Nebraska | 27 08:00 | 27 08:30 |
F | I | Omaha | Nebraska | 27 08:00 | 27 08:30 |
最佳答案
问题是 rows
实际上是单个数据单元而不是数据列。当您使用 headers
压缩它时,大小/数据不匹配。
我认为最简单的解决方案是使用 Watir 的 Table#strings
方法将表数据转换为行数据数组,可以转置以获取列数据:
def get_table_data
data = {}
customers_element.strings.transpose.each { |col| data[col.shift.to_sym] = col }
data
end
关于ruby - 如何使用 ruby 将表头和行组合到 map 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57662276/
我有一个表格,其中有一个标题行和几行内容。 现在这些实际上是 2 个单独的表: 用于标题 正文内容(另一个 iframe 的一部分) 我希望列标题的宽度应与相应的正文内容相同。 如何确保宽度相似且外观
我有一个 iPhone 应用程序,它有一个 UITableView 和一个标题。这是相当微不足道的,没有任何问题。 Android 中是否有类似 ListView 的东西?我试着搜索它,但没有找到真正
制作方法 a b c d e 始终可打印在每一页上。 我的观
如下所示: 复制代码 代码如下: //定义编码 header( 'Content-Type:text/html;charset=utf-8 ');
我有一个非常长的 HTML 表格,我需要修复标题的滚动问题,我找到了很多插件和技巧来完成它,但没有一个对我有用。 我猜对我不起作用的原因是: 所有的解决方案都将表头从表中分离出来 他们为每一列使用固定
我有一个包含 60 行(固定)的 JTable。 每当事件发生时,该行内的单元格都会更新。 当 NFC Reader 在卡上写入数据时触发该事件。这种情况每 2 或 3 秒发生一次。 如果卡片写入正确
我需要打印一个带有重复表格的 pdf,具体取决于它在第一页中工作正常的记录数量,但在下一页表格标题更改边距,这是在 TCPDF 上显示我的表格的代码; $html= '
我的表头看起来像这样:- Info blahh
我正在使用 position:fixed 在用户滚动到顶部时在我的表格中 float 一些标题,ala 这个方法:http://css-tricks.com/persistent-headers/ 在
我正在使用这个脚本来 float 我的表格标题: http://cmcqueen1975.bitbucket.org/htmlFloatingTableHeader/tables.html 它对我的元
有没有办法从逗号分隔列表构建 HTML 表头? 我正在使用反射从一个类中获取属性名称。在此之前,我定义了要从该列表中排除的属性。 var toExclude = new HashSet {
我正在将自定义 UIView 的 XIB 文件加载为 View Controller 内的 uitableview 的标题 View 。 xib 文件的文件所有者是 View Controller 。
我有以下表结构: Current New/Requested RSD &nbs
前端部分(Vue 3 + Element Plus) 1. 修改 MPS002HList.vue(主生产计划列表) a. 添加查询表单 在模板中添加查询表单,包含产品料号、品名、规格和年月的输入
给出一个查询示例,例如 import uuid from google.cloud import bigquery def query_shakespeare(): client = bigq
给出一个查询示例,例如 import uuid from google.cloud import bigquery def query_shakespeare(): client = bigq
我的表格行可以上下 move ,但我的问题是数据表行取代了表格标题(第一行)。 我想要一个固定的第一行,这样当您单击向上箭头时,您就不会向上 move 该行来替换标题。 我尝试了一些条件逻辑来检查当前
在我的React项目中,需要自定义antd表头如下 我在下面添加了示例代码。 我需要在“金额”列的标题中包含金额总和 示例代码: https://codesandbox.io/embed/great-
A test table with merged cells Average Redeyes heightweight 1.90.00340% 1.70.00
我需要动态更改 Wicket 数据表的 CSS 类。有什么建议吗? 示例代码: public class TextColumn extends PropertyColumn private stati
我是一名优秀的程序员,十分优秀!