0
私は、テキストファイルがあります。ファイル内のコンテンツを検索して一致させるにはどうすればよいですか?
<table style="background-color: #f3f3f3; font-family: Arial; font-size: 8pt; border-top: #e7e7e7 5px solid" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="padding-bottom: 20px; padding-left: 20px; padding-right: 20px; padding-top: 20px">
<p style="color: #b0b0b0"><font color="#808080" size="1"><strong>Important information</strong>: on this communication as it does not purport to be comprehensive. This disclaimer does not purport to exclude any warranties implied by law which may not be lawfully excluded. We have taken precautions to minimise the risk of transmitting software viruses, but we advise you to carry out your own virus checks on any attachment to this e-mail. We cannot accept liability for any loss or damage caused by software </p>
これは、ウェブサイトのダンプではありませんが、それはアプリケーションがファイルに入れものです。テキストファイルをチェックするための
私の方法は、次のようになります。これが動作しない
def check_email_exists(firstname, email_sub, search_string)
email_fldr="C:\\Agent\\TestMailFolder"
email_id="[email protected]"
Dir.chdir("#{email_fldr}\\#{firstname}") do
Dir.glob("#{email_id}*#{email_sub}*") do |filename|
File.open(filename) do |file|
file.readlines(filename).index("#{search_string}")
end
end
end
end
。
文字列であるsearch_string
に値を渡しています。たとえば、string = "transmitting software"
がファイルに含まれているかどうかを確認しようとしています。また、ファイルには存在しないランダムな文字列が含まれているかどうかを確認しています。この場合、ファイル内の値を見つけて一致する場合は合格、失敗した場合は失敗します。
おかげで、私がやりましたnokogiriを使うという考えを得る。 – user1126946
私は以前、これらのシナリオをテストするためにキュウリを使用していると言及していませんでした – user1126946