私が使用しているプログラムの天気予報に取り組んできましたが、ほとんどの場合、うまく機能しています。これが私がこれまでに持っているものです。(zs.stuff には注意してください。これはプログラム固有のものであり、Lua コーディングとは関係ありません。)
if not http then http = require("socket.http") end
local locale = string.gsub(zs.params(1),"%s+","%%20")
local page = http.request("http://www.wunderground.com/cgi-bin/findweather/getForecast?query=" .. locale .. "&wuSelect=WEATHER")
local location = string.match(page,'title="([%w%s,]+) RSS"')
--print("Gathering weather information for " .. location .. ".")
--local windspeed = string.match(page,'<span class="nobr"><span class="b">([%d.]+)</span> mph</span>')
--print(windspeed)
local condition = string.match(page, '<td class="vaM taC"><img src="http://icons-ecast.wxug.com/i/c/a/[%w_]+.gif" width="42" height="42" alt="[%w%s]+" class="condIcon" />')
--local image = string.match(page, '<img src="http://icons-ecast.wxug.com/i/c/a/(.+).gif" width="42" height="42" alt="[%w%s]+" class="condIcon" />')
local temperature = string.match(page,'pwsvariable="tempf" english="°F" metric="°C" value="([%d.]+)">')
local humidity = string.match(page,'pwsvariable="humidity" english="" metric="" value="(%d+)"')
zs.say(location)
--zs.say("image ./Images/" .. image .. ".gif")
zs.say("<color limegreen>Condition:</color> <color white>" .. condition .. "</color>")
zs.say("<color limegreen>Temperature: </color><color white>" .. temperature .. "F</color>")
zs.say("<color limegreen>Humidity: </color><color white>" .. humidity .. "%</color>")
私の主な問題は次のとおりです。「条件」を変更し、「画像」変数を現在のものに追加しました。一致するはずの行が Web ページから直接来ているにもかかわらず、まったく一致しません。だから、このコードが機能しないのは何が欠けているのだろうと思っています。
<td class="vaM taC">
< img src="http://icons-ecast.wxug.com/i/c/a/[%w_]+.gif"を取り出すと、
完全に条件に一致します。(何らかの理由で、上記の行を正しく表示することはできませんが、`< と img の間にスペースはありません)
誰がそれの何が悪いのか指摘できますか? パターン マッチングは別として、この行は Web ページからそのまま引用したものであることを保証します。
私が持っていた別の質問は、改行をまたいで一致させる機能です。これを行う方法はありますか?私が質問する理由は、同じページで、照合する必要があるもののいくつかが別の行に分割されており、照合したい実際のパターンがページの他の場所に表示されるためです。正確なパターンを取得するために改行全体で一致できるようにします。