Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在bash中从html中提取td/tr?_Html_Bash_Web Scraping_Html Table - Fatal编程技术网

在bash中从html中提取td/tr?

在bash中从html中提取td/tr?,html,bash,web-scraping,html-table,Html,Bash,Web Scraping,Html Table,我得到了这个页面,我想提取给定的CPU的名称,排名和基准分数 示例(“英特尔核心i5”): 我怎么能在bash中做到这一点?尝试从这样的事情开始(没有cpu过滤-不知道如何工作): #/垃圾箱/垃圾箱 卷曲http://www.cpubenchmark.net/cpu_list.php |grep'^'\ |塞德\ -e's:::g'\ -e's:::g'\ -e's:::g'\ -e's:::g'\ |cut-c2->>/home/test.txt 输出是这样的: <A HREF="c

我得到了这个页面,我想提取给定的CPU的名称,排名和基准分数

示例(“英特尔核心i5”):

我怎么能在bash中做到这一点?尝试从这样的事情开始(没有cpu过滤-不知道如何工作):

#/垃圾箱/垃圾箱
卷曲http://www.cpubenchmark.net/cpu_list.php |grep'^'\
|塞德\
-e's:::g'\
-e's:::g'\
-e's:::g'\
-e's:::g'\
|cut-c2->>/home/test.txt
输出是这样的:

<A HREF="cpu_lookup.php?cpu=686+Gen&amp;id=1495">686 Gen</A> 288 1559 NA NA
<A HREF="cpu_lookup.php?cpu=AMD+A10-4600M+APU&amp;id=10">AMD A10-4600M APU</A> 3175 388 NA NA
<A HREF="cpu_lookup.php?cpu=AMD+A10-4655M+APU&amp;id=11">AMD A10-4655M APU</A> 3017 406 NA NA
288 1559不适用
3175388NA
3017406北美

如果您想下载其他程序,可以使用我的:

所有CPU:

xidel http://www.cpubenchmark.net/cpu_list.php -e '//table[@id="cputable"]//tr/concat(td[1], " - Score: ", td[2], " - Rank: ", td[3])'
那些从英特尔开始的人…:

xidel http://www.cpubenchmark.net/cpu_list.php -e '//table[@id="cputable"]//tr[starts-with(td[1], "Intel Core i5")]/concat(td[1], " - Score: ", td[2], " - Rank: ", td[3])'
它甚至可以对它们进行排名排序(以前从未使用过该功能):


如果要下载其他程序,可以使用我的:

所有CPU:

xidel http://www.cpubenchmark.net/cpu_list.php -e '//table[@id="cputable"]//tr/concat(td[1], " - Score: ", td[2], " - Rank: ", td[3])'
那些从英特尔开始的人…:

xidel http://www.cpubenchmark.net/cpu_list.php -e '//table[@id="cputable"]//tr[starts-with(td[1], "Intel Core i5")]/concat(td[1], " - Score: ", td[2], " - Rank: ", td[3])'
它甚至可以对它们进行排名排序(以前从未使用过该功能):


严格按照页面当前格式定制的bash解决方案:

#/bin/bash
函数nextcell
{
单元格=${line%%*}
#删除关闭链接标签(如有)
单元格=${cell%}
cell=${cell##*>}
line=${line#*}
}
读行时
做
如果[[!“$line”=~cpu\u lookup.php]]
然后
持续
fi
nextcell
echo-n“$cell”
nextcell
echo-n“-分数:$cell”
nextcell
echo“-秩:$cell”
完成

严格按照当前页面格式定制的bash解决方案:

#/bin/bash
函数nextcell
{
单元格=${line%%*}
#删除关闭链接标签(如有)
单元格=${cell%}
cell=${cell##*>}
line=${line#*}
}
读行时
做
如果[[!“$line”=~cpu\u lookup.php]]
然后
持续
fi
nextcell
echo-n“$cell”
nextcell
echo-n“-分数:$cell”
nextcell
echo“-秩:$cell”
完成

Bash
绝对不是解析
HTML
的好工具。你确定你不能用别的东西吗?(
python
perl
建议我穿上我的长袍,戴上一顶向导帽)如果php是您的选择,您可能想看看这里:看起来像是另一个例子,这是一个很好的答案:这些是注释,而不是答案…“只使用perl或php”实际上是一个答案;)
Bash
绝对不是解析
HTML
的好工具。你确定你不能用别的东西吗?(
python
perl
建议我穿上我的长袍,戴上一顶向导帽)如果php是您的选择,您可能想看看这里:看起来像是另一个例子,这是一个很好的答案:这些是注释,而不是答案…“只使用perl或php”实际上是一个答案;)太棒了。从没听说过西德尔。谢谢你的解决方案。工作如预期。嗯,在我告诉任何人它之前,我把它作为我硬盘上的第五个完整的库放了将近四年……这太神奇了。从没听说过西德尔。谢谢你的解决方案。正如预期的那样。好吧,在我告诉任何人之前,我把它作为我硬盘上的第五个完整库放了将近四年。。。
xidel http://www.cpubenchmark.net/cpu_list.php -e 'for $row in //table[@id="cputable"]//tr[starts-with(td[1], "Intel Core i5")] order by $row/td[3] return $row/concat(td[1], " - Score: ", td[2], " - Rank: ", td[3])' --extract-kind=xquery