我需要從位於不同子目錄中的一堆html文件中獲取所有內嵌「data-title」屬性值。有沒有一種簡單的方法在Linux機器上執行此操作?命令行搜索所有html文件,檢索屬性值
我找到了另一個SO後類似的東西,曾試圖編輯它,但我是一個新手的sed:
sed "s/.* data-title=\"\(.*\)\".*/\1/"
我一直沒能得到這個角色很正確,我想我將需要利用額外的搜索實用程序來實現這一功能。理想情況下,我希望將所有輸出都轉換爲txt文件。
樣本:
<aside class="grid-sidebar sidebar">
<div id="listLoading"><div id="loading-listLoading" class="front-center" style="padding-top: 22%; top: 0%; display: none;"><div style="width: 42px; height: 42px; position: absolute; margin-top: 17px; margin-left: -21px; -webkit-animation: spin12 0.8s linear infinite;"><svg style="width: 42px; height: 42px;"><g transform="translate(21,21)"><g stroke-width="4" stroke-linecap="round" stroke="rgb(34, 34, 34)"><line x1="0" y1="11" x2="0" y2="18" transform="rotate(0, 0, 0)" opacity="1"></line><line x1="0" y1="11" x2="0" y2="18" transform="rotate(30, 0, 0)" opacity="0.9173553719008265"></line><line x1="0" y1="11" x2="0" y2="18" transform="rotate(60, 0, 0)" opacity="0.8347107438016529"></line><line x1="0" y1="11" x2="0" y2="18" transform="rotate(90, 0, 0)" opacity="0.7520661157024794"></line><line x1="0" y1="11" x2="0" y2="18" transform="rotate(120, 0, 0)" opacity="0.6694214876033058"></line><line x1="0" y1="11" x2="0" y2="18" transform="rotate(150, 0, 0)" opacity="0.5867768595041323"></line><line x1="0" y1="11" x2="0" y2="18" transform="rotate(180, 0, 0)" opacity="0.5041322314049588"></line><line x1="0" y1="11" x2="0" y2="18" transform="rotate(210, 0, 0)" opacity="0.42148760330578516"></line><line x1="0" y1="11" x2="0" y2="18" transform="rotate(240, 0, 0)" opacity="0.33884297520661155"></line><line x1="0" y1="11" x2="0" y2="18" transform="rotate(270, 0, 0)" opacity="0.25619834710743805"></line><line x1="0" y1="11" x2="0" y2="18" transform="rotate(300, 0, 0)" opacity="0.17355371900826455"></line><line x1="0" y1="11" x2="0" y2="18" transform="rotate(330, 0, 0)" opacity="0.09090909090909094"></line></g></g></svg></div></div></div>
<div id="list" style="position:relative;">
<div style="height: 55px;">
<h2 class="heading" style="margin-bottom: 10px">Available Records</h2>
</div>
<div style="height: 51px">
<div class="grid-3-4">
<label for="searchInput" class="infield" style="position: absolute; left: 0px; top: 55px; display: block;">Search</label>
<input id="searchInput" type="text" name="searchInput" data-title="title1" title="" style="height: 36px" class="input-long">
</div>
<div class="grid-1-4">
<select id="listStatus" name="status" class="styled input-full hasCustomSelect" data-title="Title 2" title="" style="-webkit-appearance: menulist-button; width: 104px; position: absolute; opacity: 0; height: 36px; font-size: 16px;">
<option value="all">All</option>
<option value="active" selected="">Active</option>
<option value="archived">Archived</option>
</select><span class="customSelect styled input-full" style="display: inline-block;"><span class="customSelectInner" style="width: 100%; display: inline-block;">Active</span></span>
</div>
</div>
</aside>
我知道問題是關於LINUX的。只想添加兩個xmllint命令在OSX上失敗。 – ABri 2014-11-05 17:47:17
你的失敗是什麼意思?您可以安裝'xmllint',請參閱http:// stackoverflow。com/questions/20391717 /我怎麼安裝最新版本的xmllint-on-osx-10-7-5 – 2014-11-05 17:50:31
當我嘗試運行這些時,我得到「未知選項--xpath」 ,如果所有的節點名稱都不一樣? – webaholik 2014-11-05 20:39:08