0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Nokogiri でクラス名を変更する

Last updated at Posted at 2020-12-12

The 自分用メモ🔖

やりたいこと

h1タグの中にあるspanタグのクラス名を既存のものからすべてnumberに変更したい!

やったこと

Nokogiriを使ってギコします!


require 'nokogiri'

# 👇ここは環境に合わせて上手く読み込ませてください
html = Nokogiri::HTML(File.read("ファイル名.html"))

html.search('h1 span').each do |span|
  span['class'] = 'number'
end

参考にしたもの

👇 痒いところに手が届きそうなサンプルコードがシンプルにまとまっていて、大変重宝しました✨

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?