Find tag with id including [] with Nokogiri

后端 未结 3 1070
时光说笑
时光说笑 2021-02-14 05:09

I have an html element like:

I want to search for this element by id, but it seems that nokogiri is getting confus

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-14 05:24

    Chris, try this and let me know if it works:

    doc = Nokogiri::HTML(page)
    el = doc.xpath("//div[@id='spam[500]']").first
    

    The problem is that you can't access it via CSS (even in the browser). Try setting some CSS attributes for "spam[500]" and they won't be applied. You can access via xpath however, as shown above.

提交回复
热议问题