Given:
Url - http://www.contoso.com/search.php?q={param} returns:
-html-
--body-
{...}
---div id='foo'-
----div id='page1'/-
----div id='page2'/-
----div id='page3'/-
----div id='pageN'/-
---/div-
{...}
--/body-
-/html-
Wanted:
The innerHtml of div id='foo' must be fetched by the client (i.e. Javascript).
It will be split into discrete items (i.e. div id='page1' to div id='pageN').
API Throttling prevents server-side code from pre-fetching the data, so the parsing and manipulation burden must be placed on the client.
Question:
Could Yahoo-Pipes help format the data for easier consumption?
The lack of a DOM parser gives me pause.
Are there any existing pipes that could serve as an example?
You can use the YQL module, which allows you to fetch arbitrary URLs and then parse them with XPath. A sample YQL query:
select * from html where url="http://finance.yahoo.com/q?s=yhoo" and
xpath='//div[#id="yfi_headlines"]/div[2]/ul/li/a'
Yes, it's doable with Y! Pipes. You only need two modules from the 'Operators section':
First "Sub Element" to get only the content.
Then just use the "Regex" module to extract the div content and get it through JSON from your site:
Search:
^.*?<div id="foo">(.*?)</div>.*?$
Replace:
$1
Related
I have a Drupal web service that returns a JSON response in the following format. I can easily access top level notes e.g. title. However, I also need to access the value under body. I can get body.und but not body.und.value. How do I do that? Also the HTML tags are showing as text and I can see all the slashes getting printing in my Angular View.
Update: I have been able to get the the value of the body by using $scope.body
= myresponse.data.body.und[0].value;
Now the only problem is how to process HTML in the body. My Angular framework which is Ionic is showing all the HTML tags e.g. p li etc instead of formatting them.
{"vid":"37","uid":"1","title":"Terms of Use","log":"","status":"1","comment":"1","promote":"0","sticky":"0","nid":"37","type":"page","language":"und","created":"1395878580","changed":"1501982359","tnid":"0","translate":"0","revision_timestamp":"1501982359","revision_uid":"1","body":{"und":[{"value":"THESE TERMS OF USE (\"TOU\") ARE A LEGAL CONTRACT BETWEEN YOU (\"USER\") AND
$scope.body = myresponse.data.body.und[0].value; helped me get access to the value of the body of the node.
ng-bind-html="body" helped me get access to the body of the HTML.
I am using angular 1.5 and using translate to externalize my strings to a separate json file.
The translated strings sometimes fail to load and the path of the string is displayed instead.
ex: instead of displaying "Hello World" it displays something like "greet.hello".
This is not a regular occurrence and goes away when I refresh the page.
Not sure whether this is a file load issue.
Remove the single quote.
Its should be {{greet.hello | translate}}.
it's better practice to use directive.
Angular runs every single filter twice per $digest cycle once something has changed.
So you can do directive instead:
<h1 translate="{{greet.hello}}" ></h1>
http://www.scientiamobile.com/page/angularwit
Want to be able to do something like this:
<img-wit ng-src="{{trustSrc(profile.pic)}}" w="100"/>
The picture isn't rendering however, although the blank space is sized correctly. Is it possible to use angular directive version of img-wit with ng-src?
UPDATE:
Determined the easiest way to use img-wit is not to implement angularjs directive at all. Instead, just append appropriate img-wit link prefix inside controller.
Support to ngSrc directive has been added in the 0.9.1 version: https://github.com/WURFL/angular-wurfl-image-tailor/releases/tag/0.9.1.
Syntax like the follow is now supported:
<img-wit ng-src="{{myUrl}}"></img-wit>
where {{myUrl}} is the url of the trusted image to load.
Please check https://github.com/WURFL/angular-wurfl-image-tailor#how-to-use-it for further details.
Disclaimer: I work for ScientiaMobile
We are using DPS's PXPay to generate payments for our app.
On a successful transaction the url that is provided looks like
http://ourapp.com/checkout/complete?result=v5eX-DlMlfGe2FUcPeZgCFiKhZwgmCVhlTfL-rtnPszpe8S_6MYJMbVPDK14h7KxQM6xfKYUnXhz_RcSOHqw4VwHX97GU9XINHwh9DFt6aDHOLMvdAnSwZost5H2aOQlZgMESDzlwNGx_lfgeLba2Us41x437J3PWTJ_LLJVK4OY_7K4c6rxQ88Mve7FfoYd7P8CAZWxyHbC-wxCyLiocw4_NQ_34ct-IAsR1MM3C2OkPijfBAk-l72rOOMWGp8EoLpdOHyT0uITvsdjMvOFIHIMnSdVs2JFCslAmTRMDl4jkb5ezBf9wKZuo91KgII0kd9dFJMFCm7evt-X0ykLw_vjcgg85kZoRbDvi89nEGiWmFLVKM_xVgZYufeMMudOGRcHgi4i-RZJ4mml2JMzN2OtJKyQdpxuC-3b9KfnRbyy_F75Gak5fwJIf4tvo6VNJKUJuBtKYKafPyH_YJU4HQMeHP8uO0-FhMN3mzRCmGjvExuqx1BhA67R35pmaTbyxz-06JEvIqzf8FTftoBowLSeu37KtNmagZ8cJpMlCe4kUaFY4v6ZTx7h9rYx37oYtZNsSR1t3KDFzQYRs5LAg8RQ==&userid=OurDevId
This is definitely the request that is coming into the browser. BUT what is displayed in my browser URL bar... and what angular reads for the "result" token is this...
http://ourapp.com/checkout/complete?result=v5eX-DlMlfGe2FUcPeZgCFiKhZwgmCVhlTfL-rtnPszpe8S_6MYJMbVPDK14h7KxQM6xfKYUnXhz_RcSOHqw4VwHX97GU9XINHwh9DFt6aDHOLMvdAnSwZost5H2aOQlZgMESDzlwNGx_lfgeLba2Us41x437J3PWTJ_LLJVK4OY_7K4c6rxQ88Mve7FfoYd7P8CAZWxyHbC-wxCyLiocw4_NQ_34ct-IAsR1MM3C2OkPijfBAk-l72rOOMWGp8EoLpdOHyT0uITvsdjMvOFIHIMnSdVs2JFCslAmTRMDl4jkb5ezBf9wKZuo91KgII0kd9dFJMFCm7evt-X0ykLw_vjcgg85kZoRbDvi89nEGiWmFLVKM_xVgZYufeMMudOGRcHgi4i-RZJ4mml2JMzN2OtJKyQdpxuC-3b9KfnRbyy_F75Gak5fwJIf4tvo6VNJKUJuBtKYKafPyH_YJU4HQMeHP8uO0-FhMN3mzRCmGjvExuqx1BhA67R35pmaTbyxz-06JEvIqzf8FTftoBowLSeu37KtNmagZ8cJpMlCe4kUaFY4v6ZTx7h9rYx37oYtZNsSR1t3KDFzQYRs5LAg8RQ&userid=OurDevId
If you look closely... the two '==' are being taken off the end of the "result" token string.
I've tested in non angular applications and this isn't happening. Why does angular do this and how do I prevent it?
Angular cannot handle == because of its $location's search parsing. Just visit : https://angularjs.org/?foo==123 and the url will change to https://angularjs.org/?foo=
The same will not happen on a non-angular page.
Solution: Either patch angular OR HTML encode the section after ?result=
Depending on what you're trying to do with the URL that is returned, it might be simpler to just set window.location directly instead of working through Angular. This bypasses the query-string parsing in $location that's stripping the double equals.
I need to remove all br tags from the json data I am working with before rendering to the template.
Im wondering if there is a pre-existing angular directive which could be used for this, or if there is a way to do it by creating a custom filter. The documantation on filters doesnt seem to be easily adaptable to this usecase.
Do you need to remove <br>s from a specific object property like remove HTML from a string (in JSON response) or do you need to remove them from all properties of the JSON object?
You should be able to just put some JavaScript code into a custom filter (the custom filter would return either a modified JSON object or a new object), and then call that filter from your HTML when you want to display the JSON.
If you are displaying different parts of your JSON object using different ng-repeat, ng-show, etc. directives, it might make more sense to filter the JSON once in your controller, then use the filtered version in the HTML/template. A little more information about your actual use case would help.