Вопрос

i want to get the parentID from this.

<div class="module-head" onclick="getURL('/DU/initAction.do?parentId=1063&categoryType=6')"></div>

how can i achieve this?

Это было полезно?

Решение

The setup:

html = <<-EOF
<div class="module-head" onclick="getURL('/DU/initAction.do?parentId=1063&categoryType=6')"></div>
EOF

Hpricot:

doc = Hpricot html

or Nokogiri:

doc = Nokogiri::HTML html

Interestingly, it's the same in both:

doc.at('div')[:onclick][/parentId=(\d+)/, 1]
#=> "1063"
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top