Hello stackoverflow Community,
I am working on a Survey which uses Text-To-Speech components. Usually they look like this:
<img src="picture.jpg" border="1" input onclick="responsiveVoice.speak('spoken_Text_here', 'Deutsch Female');" class="button1"> Text_behind_Button?
Now, I have a Database with all the Elements which will be "spoken" (or: to be used in the TTS script) and insert them in my survey software with
$key = 'A1';
$tts = dbGet($key);
So far so good. Now I would like to take the first element of the array $tts und put it in the TTS script.
<img src="picture.jpg" border="1" input onclick="responsiveVoice.speak('<?php $tts[0] ?>', 'Deutsch Female');" class="button1"> Text_behind_Button?
As a result I would like, that when you click on the button, the script takes the string from the Database and inserts it the TTS code. This way above obviously doesn't work. So I guess that I have to change the array in a string which can be read. Unfortunatly, I dont have the knoledge how to do that.
Ideas, hints and criticism (more or less) are welcome!
Best wishes
Related
I am trying to parse data from the following website (https://www.fundsquare.net/security/information?idInstr=275136)
I want to display the price of the fund in Google sheets. However, when using the 'importxml' function I get an error that the "imported content is empty". Anybody know what I can do to fix it?
Ways I tried the function:
=IMPORTXML("https://www.fundsquare.net/security/summary?idInstr=275136" ,"//*[#class ='surligneorange']" )
=IMPORTXML("https://www.fundsquare.net/security/information?idInstr=275136" , "//*[#id='content']/table[2]/tbody/tr/td[3]/span[1]")
=IMPORTXML("https://www.fundsquare.net/security/information?idInstr=275136" , "//*[#id='content']//span[1]")
I keep on getting the same error. When looking for this error I get the difference between static and dynamic data. This data changes so I guess its dynamic but i'm not sure how that would impact the formula.
I have been trying some things with script editor but no success. Also trying something with RegExp but couldn't get any further than the examples. My knowledge of scraping is limited so any tips and tricks when trying to parse data is greatly appreciated!
Any help would be greatly appreciated!
Edit:
Within script editor I tried the following code:
function importdata() {
var found, html, content = '';
var response = UrlFetchApp.fetch("https://www.fundsquare.net/security/information?idInstr=275136");
if (response) {
html = response.getContentText();
if (html) content = html.match(/<span class="surligneorange">(.*)<\/span>/)[0];
}
Logger.log(content);
}
This gives me the following log output:
[20-06-05 07:44:58:529 PDT] <span class="surligneorange">31.15 EUR</span> <span style="color:#DD0000;text-align:left;padding:4px 0;"> -0.67 % <img src="/images/share/variationNegative.gif" style="vertical-align:middle;"/></span></td></tr></table><div id="onglet">DocumentsTaxesDividendsHist. PricesPriceOrder Ref. Data<a class="selected" href="/security/information?idInstr=275136">Security Information</a>Overview<br class="clear_r"/></div><div id="blocresume"><table class="portlet100pct" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top" class="portletleft50pct"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top" class="portletBordGris"><div style="position: relative; left: 1px;" class="bloctitle"><img src="/Fundsquare/images/share/x.gif" border="0" height="1" width="1" /></div><DIV class="bloctitle" style="position: relative; top: -21px; right: 1px;"><span style="top: 3px;" >General information</span>
The value 31.15 is what I want to scrape. How can I get this value in my spreadsheet?
Edit 06/06 10:14:
further questions
Could you please help me understand what you changed. What exactly is the difference between what I tried to match and what you matched.
mine:
if (html) content = html.match(/<span class="surligneorange">(.*)<\/span>/)[0];
yours:
if (html) content = html.match(/<span class="surligneorange">([\d.]*).*?<\/span>/)[1];
and:
if (html) content = html.match(/<span class="surligneorange">([\d.]*).*<\/span>/)[1];
What is the difference between my [0] and your [1]. is it that you only request the first value?
What is the difference between my .* and your ([\d.]*).* or [\d.]*).*????
My knowledge from javascript is not so good so I am unsure what it does. Thanks for the help!
How about this answer?
Unfortunately, when I saw the HTML and your formulas, I thought that the value might not be directly retrieved by IMPORTXML. So I think that your approach to use Google Apps Script can be used for retrieving the value you expect. But I think that your script has the modification points a little for achieving it. In this answer, I would like to propose the modification points of your Google Apps Script.
In your case, I think that the method of match and the regex are required to be modified.
Modified script
When your script is modified, please modify as follows.
From:
if (html) content = html.match(/<span class="surligneorange">(.*)<\/span>/)[0];
To:
if (html) content = html.match(/<span class="surligneorange">([\d.]*).*?<\/span>/)[1];
In my test, the modified script returns 31.15.
I think that <span class="surligneorange">([\d.]*).*<\/span> can be also used.
Script for putting to a cell in Google Spreadsheet
As the modified script for putting to a cell in Google Spreadsheet, from your situation, I thought that you might want to use this as the custom function. If it's so, how about the following modified script?
When your script is used as the custom function, please rename the function name from importdata to others. Because importdata has already been used as the built-in function.
function sample() {
var found, html, content = '';
var response = UrlFetchApp.fetch("https://www.fundsquare.net/security/information?idInstr=275136");
if (response) {
html = response.getContentText();
if (html) content = html.match(/<span class="surligneorange">([\d.]*).*<\/span>/)[1];
}
return content;
}
In this case, when =sample() is put to a cell, the value of 31.15 is put to the cell. If you want to put the value as the number, please modify return content to return Number(content).
Reference:
match()
Added:
For your additional question, I added the answers as follows.
In your script, html.match(/<span class="surligneorange">(.*)<\/span>/)[0]; returns the full match. When you want to retrieve the group, in this case, it's html.match(/<span class="surligneorange">(.*)<\/span>/)[1];. But, in this regex, the retrieved value is 31.15 EUR</span>.....General information</span>. I thought that the reason of your issue is this.
In order to retrieve the value of 31.15 EUR, .* is modified to .*?. By this, the matched value is from <span class="surligneorange">31.15 EUR</span>.....General information</span> to <span class="surligneorange">31.15 EUR</span>.
But in your goal, you want to retrieve only 31.15. So I used ([\d.]*).*. By this, 31.15 of <span class="surligneorange">31.15 EUR</span>.....General information</span> is retrieved. When ([\d.]*).*? is used, 31.15 of <span class="surligneorange">31.15 EUR</span> is retrieved.
So, in the case of <span class="surligneorange">([\d.]*).*?<\/span>, <span class="surligneorange">31.15 EUR</span> is matched. And ([\d.]*) is 31.15.
In the case of <span class="surligneorange">([\d.]*).*<\/span>, <span class="surligneorange">31.15 EUR</span>.....General information</span> is matched. And ([\d.]*) is 31.15.
Reference:
Regular expressions
My PHP/HTML/Javascript skills are 0 but I have managed to create a site using a default template which I have modified.
What I am trying to accomplish is to have the browser print out the Cookie Name and Value if it exists. This is for a lab exercise that I'm currently working on. The lab itself is not how you program but rather how you configure Cookie Persistence and as part of the lab I want the student to easily display the cookie on the webpage.
Previous examples have been with HTML/JavaScript and the following code:
<script language="javascript">
function showCookieLink() {
var ele = document.getElementById("CookieLink");
ele.style.display = "block";
}
</script>
<BODY bgColor="#0066FF" onload="javascript:if (document.cookie) showCookieLink()">
<tr>
<td colspan="2" align="center" vAlign="top">
<font face=Arial>
<div id="CookieLink" style="display: none;"><b><font color=#0000f0>Display Cookie</b></div>
</font>
</td>
</tr>
This previous example have been brilliant. It will print out the clickable link "Display Cookie" (if a cookie exists) and when clicked it will pop up a new smaller window with the Cookie Name and Value.
For some reason this does not work anymore. I have tried several different browsers but they all act the same. JavaScript is enabled on the user.
I have been trying different types of preformatted-codes to fix this but none work (or I just suck at programming/scripting).
Can you guys please help me with this? Perhaps you can print out an example code that I can copy/paste into my current php code?
Thanks in advance!
According to this post, document.cookies will only work in a web server, not in just html that is served up from the file system. Does your url look like http://localhost or file:///your/file/here.html? It should look like the http:// one.
You also have some issues with your code. you dont close the second font tag, <script> should either be in a <head> or <body> tag, your <body> tag shouldn't be capitalized. Look here for a basic template.
I am an admin on an online roleplaying game, and we recently made the transition from some sort of Frankencode to javascript. While I have the basics down, there is a problem I have encountered that I am not sure how to fix.
We have macros on the game, where you can move multiple rooms by typing the direction with a space, a semi-colon, and another space between directions. I've created an atlas that has a long list of macros to help the players of the game move around faster and more efficiently. My main problem is, everything worked with the Frankencode, but Javascript is not recognizing the iframe in my new code.
I would really like an alternative to iframes where I don't have to rely on an outside website for this script, but my journey into that hopeful line of thought just led to a bunch of bright red, angry errors and the command breaking. I substituted the iframe for a contentedtable and the game just was not having it!
Below is my code. Keep in mind that everything works except the iframe.
Thanks in advance! :)
var macaroni = "<center><img src=http://i188.photobucket.com/albums/z46/roseblossomsnapdragon/items/atlas.jpg><BR><image src= http://i188.photobucket.com/albums/z46/roseblossomsnapdragon/amazingatlas-1.jpg~original><BR/> <b><font color=blue><u><b>IF ANY OF THESE ARE BROKEN, INFORM VICTORIA.</font></u></b></b><BR> <table border=0> <tr> <td Valign=top bgcolor=white> <IFRAME name=inlineframe src=http://karchanhelp.webs.com/other%20stuff/otherotherstuff/macaroni.htm width=550 height=400 marginwidth=0 marginheight=0 frameborder=0 scrolling=auto></IFRAME></td> <td Valign=top bgcolor=white><form method=post action=> <textarea name=comments cols=80 rows=21> Copy and paste here to build longer macros. </textarea> </form></td> </tr> </table><P> </center>";
var macaroons = "<center><img src=http://i188.photobucket.com/albums/z46/roseblossomsnapdragon/items/atlas.jpg><BR><image src= http://i188.photobucket.com/albums/z46/roseblossomsnapdragon/amazingatlas-1.jpg~original><BR/> <b><font color=blue><u><b>IF ANY OF THESE ARE BROKEN, INFORM VICTORIA.</font></u></b></b><BR> <table border=0> <tr> <td Valign=top bgcolor=white> <IFRAME name=inlineframe src=http://karchanhelp.webs.com/other%20stuff/otherotherstuff/macaroni.htm width=550 height=400 marginwidth=0 marginheight=0 frameborder=0 scrolling=auto></IFRAME></td> <td Valign=top bgcolor=white><form method=post action=> <textarea name=comments cols=80 rows=21> Copy and paste here to build longer macros. </textarea> </form></td> </tr> </table><P> </center>";
function command(person, totalcommand) {
if (person.isAttribute("macaroons"))
{
person.personal(macaroons);
person.sendMessage("%SNAME begin%VERB2 studying an atlas out of nowhere.<BR>");
return;
}
person.personal(macaroni);
person.sendMessage("%SNAME begin%VERB2 studying an atlas out of nowhere.<BR>");
return;
}
The alternative to iframes is AJAX(Asynchronos Javascript and XML) which lets you load pages and data from a server and you can handle the results for that and insert the response back into your page.
The best pages for learning about Javascript are from the Mozilla Developer Network and this link especially will help you learn more about ajax.
However there are libraries you can download, such as jQuery that help simplify a lot of tasks including loading and storing html and more.
If you need to store a website you can do the following:
Include jQuery in the HEAD:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Create a div(or other container for storing) with any id you want(should be unique):
<div id="loadingArea"></div>
Include a script at either the end of the page or end of the head to ensure that jQuery has loaded
<script>
$(document).ready( //Will run the following function when the html document is ready
function() {
var url = "http://karchanhelp.webs.com/other%20stuff/otherotherstuff/macaroni.htm"; //Load the page you want.
var portion = "body >" //select the portion of the page you need to eliminate duplicate html, head, and body tags
//This is a jQuery selector similar to css meaning select all children (>) of body
//Here we tell jQuery to select the element with id(#) loadingArea and load the
//portion of the url.
$('#loadingArea').load(url+" "+portion);
}
); //End of ready call
</script>
I was wondering if there is a way to copy and paste some part of the text from a third party web page. My boss asked me to enter a group of text (50, 100, 200) one-by-one into this website: http://fbatoolkit.com/chart_details?category=T2ZmaWNlIFByb2R1Y3Rz&rank=500 and copy/paste the information "3 (30 days avg)" into another file. The "rank=500" part is the query string in the url. And I also know where the info, in the html source code, is. It is here:
<div style="margin: 20px">
Estimate sales per day for the rank
<input type="text" name="rank" value="500" />
in this category.
<input type="submit" value="Estimate" />
<table width="200">
<tr>
<td>
3 (30 Days Avg)
</d>
</tr>
<tr>
<td>
More than 2 (Last Day)
</td>
</tr>
</table>
</div>
</form>
I was wondering if there is a way to recursively access the website and copy/paste that part of text into another file. I know it is probably not the smartest way to do things but please help, the almighty stack overflow! I really appreciate that.
So I don't write python but I'll give it a shot. These types of tasks are usually very easy to accomplish with Python. So, I'll give you the general language constructs that I would use complete with links to accomplish this.
General Steps
Set up array of categories
Set up array of ranks to use
For loop through each category and then nested loop through each rank
Within this inner loop, query the web page like this: see This Answer for more options to opening and reading URLS
page = urllib.request.urlopen("URL HERE").read()
Then use RegEx to find the text you're interested in, by doing something like this (Note - the below RegEx was created assuming "(30 Days Avg)" was a static string, which it seemed like from page you supplied. You can re-append this text to the end of the grouped item if you'd like):
match = re.search("(\w+) (30 Days Avg)$", string)
extractedText = match.groups(0)
Append text to file of your choice per This Answer
Close out your loops
Sorry this wasn't more cut-and-paste code. Also the SO text editing syntax doesn't seem to handle code inside lists very well. "extractedText... " should be on its own line.
can anybody tell me what am I doing wrong?
I want to retrieve all my alfresco sites with this code (this should work):
model.sites = siteService.listSites(null, null, 0); // return type= List<Site>
And now i want to retrieve this list model.sites in my HTML freemarker template like this:
<body> ${sites} </body>
How can I view this sites list. I know i am getting it wrong in my ftl, but can't find a solution how to retrieve it.
You'll need to loop over the sites in your freemarker. Assuming you wanted a list of the site names, with commas between them, then your freemarker would instead want to look something like:
<body>
<#list sites as site>
${site.shortName}<#if site_has_next>,</#if>
</#list>
</body>