我通常會將散列轉換爲下拉。但是這一次,我想做相反的事情。有誰知道如何使用正則表達式來做到這一點?或任何其他方式。請注意,下拉列表包含optgroup和options。我只想要這個選項,這樣id就是散列的關鍵,而下拉的值就是散列的值。Perl:如何將下拉轉換爲哈希?
例如,如果我們有一個下拉如下:
<select>
<optgroup label=fruits>
<option id=1>Apple</option>
<option id=2>Orange</option>
<option id=3>Pineapple</option>
<optgroup label=stuff>
<option id=4>Chair</option>
<option id=5>Board</option>
</select>
我想這是
1=> "apple", 2=>"Orange",3=>"Pineapple",4=>"Chair", 5=>"Board"
你們是不是要問如何使用正則表達式解析HTML? http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 –
如果您正在嘗試將XML文檔加載到Perl哈希中,請使用XML :: Simple模塊al cpan –
以下是如何使用Perl解析HTML的示例:http://htmlparsing.com/perl.html –