[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: how to get specific text from website via androlua
- From: Sean Conner <sean@...>
- Date: Fri, 21 Apr 2023 05:04:55 -0400
Your reply was stuff into the Subject: header of this email. I have
copied the subject line, and pasted it in below (that is, what there is of
it). Please, if you can, don't paste your entire message into the subject
line as it does get truncated send sending, and it's hard to read.
With that said ...
It was thus said that the Great Rana Ayaz once stated:
>
> I am pasting the codes of two functions below some people are using this
> method to get specific text from website but i could not be understand
> what's the method used here can anyone guide me properly about it?
Someone using adrolua would give a better answer, but I'll try.
> require "import"
My educated guess here is this loads a module named "import", that's only
available for androlua. I would also guess this is using Lua 5.1 and that
the import module goes into the global name space. If this doesn't mean
anything to do, then you have two issues: 1) you need to learn Lua (this
mailing list can help you here), and 2) you need to learn the androlua
environment (this mailing list probably can't help you much, if at all).
> import "android.content.Intent"
> import "android.net.Uri"
> import "com.androlua.*"
This is androlua specific code here, and as a guess, this loads more
modules into Lua. These, again, are NOT standard Lua modules, but are
specific to androlua, and probably to Android itself.
> local url = "https://www.timeanddate.com/weather/pakistan/lahore"
This is just the URL being referenced.
> Http.get(url,function(status, data)
Http.get() is, again, not a standard Lua module, but was probably defined
by one of the import statements above. If I had to guess, this fetches the
URL listed above using the HTTP GET method. If that doesn't mean anything
to you, you need to 3) learn about HTTP (which is beyond the scope of this
mailing list).
The first parameter is the URL, the second one is a function that is
(again, an educated guess) called as soon as the web page has been loaded.
> if status == 200 then
If the HTTP GET request returned a 200 status, then
> io.open("/storage/emulated/0/Download/html_data.txt","w"):write(data):close()
This opens the file "/storage/emulated/0/Download/html_data.txt" using a
standard Lua function io.open(), and writes the page, then closes the file,
all on one line. This is probably due to saving a copy of the page in case
things go wrong and the programmer can check the page as it was received and
modify the code accordingly.
> local loc = string.match(data, "banner__title>Weather%sin%s(%a+)")
> local temp = string.match(data, "(%d+)%D+°")
> local type = string.match(data, "class=mtt%stitle=\"(%a+)%.\"")
> local t_high = string.match(data, "Forecast:%s(%d+)%s/%s%d+")
> local t_low = string.match(data, "Forecast:%s%d+%s/%s(%d+)")
> local wind = string.match(data, "Wind:%s(%d+
These lines (and due to the Subject: header being truncated, it just ends
part way through) use a standard Lua function string.match() looking for
data in the page returned. This is web scrapping---using a program to fetch
a web page and extract data from it.
The first line scans through the page looking for the literal text
"banner__title>Weather in" (here, the '%s' represents spaces) and then
captures (the parenthesis) text ('%a' matches letters). The variable loc
will contain the text "Lahore" (even though the particular text is "Weather
in Lahore, Pakistan"). The other lines do similar things.
-spc
- References:
- how to get specific text from website via androlua, Rana Ayaz
- Re: how to get specific text from website via androlua, GoldenKnightFly
- Re: how to get specific text from website via androlua, Fidel H Viegas
- Re: how to get specific text from website via androlua, Rana Ayaz
- Re: how to get specific text from website via androlua, Michal Kottman
- Re: how to get specific text from website via androlua I am pasting the codes of two functions below some people are using this method to get specific text from website but i could not be understand what's the method used here can anyone guide me properly about it? require "import" --import "android.content.Intent" import "android.net.Uri" --import "com.androlua.*" local url = "https://www.timeanddate.com/weather/pakistan/lahore" -- الرجائ عدم اجرائ اي تغيير بعد هذه النقطة Http.get(url,function(status, data) if status == 200 then io.open("/storage/emulated/0/Download/html_data.txt","w"):write(data):close() local loc = string.match(data, "banner__title>Weather%sin%s(%a+)") local temp = string.match(data, "(%d+)%D+°") local type = string.match(data, "class=mtt%stitle=\"(%a+)%.\"") local t_high = string.match(data, "Forecast:%s(%d+)%s/%s%d+") local t_low = string.match(data, "Forecast:%s%d+%s/%s(%d+)") local wind = string.match(data, "Wind:%s(%d+, Rana Ayaz
- Prev by Date:
Re: how to get specific text from website via androlua I am pasting the codes of two functions below some people are using this method to get specific text from website but i could not be understand what's the method used here can anyone guide me properly about it? require "import" --import "android.content.Intent" import "android.net.Uri" --import "com.androlua.*" local url = "https://www.timeanddate.com/weather/pakistan/lahore" -- الرجائ عدم اجرائ اي تغيير بعد هذه النقطة Http.get(url,function(status, data) if status == 200 then io.open("/storage/emulated/0/Download/html_data.txt","w"):write(data):close() local loc = string.match(data, "banner__title>Weather%sin%s(%a+)") local temp = string.match(data, "(%d+)%D+°") local type = string.match(data, "class=mtt%stitle=\"(%a+)%.\"") local t_high = string.match(data, "Forecast:%s(%d+)%s/%s%d+") local t_low = string.match(data, "Forecast:%s%d+%s/%s(%d+)") local wind = string.match(data, "Wind:%s(%d+
- Next by Date:
Re: [ANN] Lua 5.4.5 (rc2) now available
- Previous by thread:
Re: how to get specific text from website via androlua I am pasting the codes of two functions below some people are using this method to get specific text from website but i could not be understand what's the method used here can anyone guide me properly about it? require "import" --import "android.content.Intent" import "android.net.Uri" --import "com.androlua.*" local url = "https://www.timeanddate.com/weather/pakistan/lahore" -- الرجائ عدم اجرائ اي تغيير بعد هذه النقطة Http.get(url,function(status, data) if status == 200 then io.open("/storage/emulated/0/Download/html_data.txt","w"):write(data):close() local loc = string.match(data, "banner__title>Weather%sin%s(%a+)") local temp = string.match(data, "(%d+)%D+°") local type = string.match(data, "class=mtt%stitle=\"(%a+)%.\"") local t_high = string.match(data, "Forecast:%s(%d+)%s/%s%d+") local t_low = string.match(data, "Forecast:%s%d+%s/%s(%d+)") local wind = string.match(data, "Wind:%s(%d+
- Next by thread:
Re: how to get specific text from website via androlua
- Index(es):