HTTP Request -> jQuery Parser

181 views
Skip to first unread message

Сергей Ру

unread,
Apr 17, 2021, 11:33:42 AM4/17/21
to Tasker
Need help! I create a problem of collecting / parsing / scraping the weather data on the current day from www.foreca.com and the subsequent voice output. For parseing / scraping, I decided to use JavaScriptle, and the JS jQuery library. And to receive the DOM (HTML) web pages using HTTP Request, since JavaScript is done very difficult to do this due to the CORS error. The parser script itself, checked it in the browser (downloaded HTML pages and attached this parser-script to it with the data output to the console for visibility), as well as in Node JS (used with the Cheerio library). Here is the abbreviated version of the script (the full version is oversaturated with variables):

$(function() {
var town = $('div').eq(27).children('h1').text();
var temper = $('div').eq(30).children('span').text();
});

And the abbreviated version of the descriptor (the full version is oversaturated with variables):

Weather (24)
A1: HTTP Request [ Method:GET URL:https://www.foreca.com Headers: Query Parameters: Body: File To Send: File/Directory To Save With Output: Timeout (Seconds):30 Trust Any Certificate:On Automatically Follow Redirects:Off Use Cookies:On ]
A2: JavaScriptlet [ Code:$(function() {
var town = $('div').eq(27).children('h1').text();
var temper = $('div').eq(30).children('span').text();
}); Libraries:https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js Auto Exit:On Timeout (Seconds):10 ]
A3: Say [ Text: Temperature in %town: %temper,
Engine:Voice:default:default Stream:3 Pitch:5 Speed:5 Respect Audio Focus:On Network:Off Continue Task Immediately:Off ]

I can't understand how to rain jQuery Parser (DOM) HTML pages located in the% http_data variable ???
I apologize for my bad English. This google translator.

João Dias

unread,
Apr 19, 2021, 6:10:50 AM4/19/21
to tas...@googlegroups.com
Hi. The latest Tasker beta can read HTML directly. Does that help? :) 

https://www.reddit.com/r/tasker/comments/lgxj9w/dev_tasker_5120beta_native_json_and_html_reading/

Thank you for your contact.

   Join: connect multiple devices (send pushes, remote SMS, notifications) on Android, Windows, Mac, Linux
   Tasker: customize/automate anything on your phone!
   AutoApps: add advanced functionality to Tasker via plugins

     

João Dias


Сергей Ру

unread,
Apr 19, 2021, 7:42:19 AM4/19/21
to Tasker
I do not use beta version of the application. Is there a solution for version 5.11.14 (Android 10)?

понедельник, 19 апреля 2021 г. в 13:10:50 UTC+3, joaomgcd:

João Dias

unread,
Apr 19, 2021, 7:47:13 AM4/19/21
to tas...@googlegroups.com
Hi again.

Ok, does this help?

var parser = new DOMParser();
var htmlDoc = parser.parseFromString("<html><div></div></html>", 'text/html');
htmlDoc.querySelector("div")


Thank you for your contact.

   Join: connect multiple devices (send pushes, remote SMS, notifications) on Android, Windows, Mac, Linux
   Tasker: customize/automate anything on your phone!
   AutoApps: add advanced functionality to Tasker via plugins

     

João Dias

--
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tasker/82ad41c4-7ac2-4e1b-98f5-cc9efc49ddfan%40googlegroups.com.
Message has been deleted

Сергей Ру

unread,
Apr 20, 2021, 3:13:23 AM4/20/21
to Tasker
Happened!!!
Made like this (the abbreviated version, the full version is oversaturated with variables):

Weather (28)
    A1: HTTP Request [  Method:GET URL:https://www.foreca.com Headers: Query Parameters: Body: File To Send: File/Directory To Save With Output: Timeout (Seconds):30 Trust Any Certificate:Off Automatically Follow Redirects:Off Use Cookies:Off ]
    A2: JavaScriptlet [ Code:var el = document.createElement( 'html' );
    el.innerHTML = http_data;
    var town = el.getElementsByTagName( 'div' ) [27].querySelector( 'h1' ).textContent;
    var temper = el.getElementsByTagName( 'div' )[30].querySelector( 'span' ).textContent;

     Libraries:https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js Auto Exit:On Timeout (Seconds):10 ]
   
A3: Say [ Text: Temperature in %town: %temper,
Engine:Voice:default:default Stream:3 Pitch:5 Speed:5 Respect Audio Focus:On Network:Off Continue Task Immediately:Off ]

Some data I get on a foreign language for me (for example:  %town ), can I somehow translate them to my tongue?
вторник, 20 апреля 2021 г. в 00:21:13 UTC+3, Сергей Ру:
I can not do it.

понедельник, 19 апреля 2021 г. в 14:47:13 UTC+3, joaomgcd:
Reply all
Reply to author
Forward
0 new messages