Extract first url or image from a webpage in objective c - ios

Is there a way to extract any link from the URL of the page and open it in UIWebView.
I already know how to display a webpage on ios screen:
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http:google.com]]]
Example: Suppose a string is given by the user "ABC". The code I want to write should search say "ABC" in google and open the first link that it shows. <- This all to be done automatically. All that user care is give the input string.
Please help regarding the procedure and steps one should follow.
Thanks

If I undestood what you want, you can load the url content into a string
[NSString stringWithContentsOfUrl: [NSURL URLWithString:#"http://mydomain.com"] encoding: NSUTF8StringEncoding error: nil];
and after that you need to know the html struct to extract the link (result) that you want. Eg: for google, you can find a div <div id="ires"> that has ol and li elements that contains the links. So you just load the webview content with the result link, like you said above.

Related

Styling a vaadin Component (Dialog) with CSS file

I have a Dialog that retrieve informations from an endpoint (String of information) but I have a Problem with style this dialog, because all these informations appear untidily!
For example to be clear, I have this endpoint, that it helps me to retrieve a Data about Mobile, and want to show this Data in a Dialog (BUT the Style should like Screenshot Nr. 1), but my Problem is that the data appears as Preview (Screenshot 2).
You can use the Html component with a pre tag where you put the formatted JSON:
Html pre = new Html("<pre>" + formattedJson + "</pre>");
To format the JSON String you can use this:
String prettyJson = mapper.writerWithDefaultPrettyPrinter()
.writeValueAsString(mapper.readTree(inputJson));
Find more examples here: https://roytuts.com/how-to-pretty-print-json-in-java/

typo3 tsconfig url parameters media

We are using Typo3 7.6.
We use a simple text and media Element to embed youtube videos.
Those youtube video-embed links do need paramters (like rel=0), but I see no option to imput them and I do not find any typoScript where I can set those parameters in any help. Putting the paramters directly into the URL that I enter in the element does not work, merely the ID is parsed.
Is there a simple way to do this?
You need to set buttons.link.queryParametersSelector.enabled to true in your page TS-Config.
To do this edit your rootpage(normally id=1) and go to tab Resources.
Fill in the following code to the field Page TSConfig.
RTE.default.buttons.link.queryParametersSelector.enabled = 1
After saving you should see an additional field called "Additional link parameters" when you use the link wizard.
Reference: EXT: rtehtmlarea -> buttons.link.queryParametersSelector.enabled
I assume you use fluid styled content? If so, the gallery processer could be configured via TypoScript setup like this:
lib.contentElement.settings {
media {
additionalConfig {
no-cookie = 1
modestbranding = 1
relatedVideos = 0
showinfo = 0
}
}
}

Grab text only from Wordpress website, display on iOS app

Is there any way I can grab only the title, author, date, and text from a Wordpress website's article through its RSS feed? I'm trying to create an iOS app (Xcode) that can display this information.
EDIT:
I am currently using rshankras' BlogReader code to fetch articles from the website, but it displays the actual link to the page. I'm looking to be able to access the article's title, author, date, and text, and be able to format it myself, instead of having the actual site show up. What tools can I use to do this, if feasible?
This is the website in question.
You are using a ready-made app so I think, you will have to modify it yourself to serve your purpose. For showing content as you want, you need to manipulate the HTML content instead of viewing it in WebView.
Inside your app, the WebView element is in PostViewController.swift file. So if your put the following code in line number 24 of that file, you will get the URL that is being requested.
println(url)
This code prints the output in console. Now as you know the url. You can simply fetch the HTML Code and manipulate and show it as your heart want using the following way:
let pageurl = NSURL(string: url) //you got the url variable 3 lines above
let task = NSURLSession.sharedSession().dataTaskWithURL(pageurl!) {
(data, response, errror) in
if error == nil {
var urlContent = NSString(data: data, encoding: NSUTF8StringEncoding) as NSString!
println(urlContent)
}
}
This will print the full HTML Code string encoded using UTF-8.
Now in the postViewController, instead of using WebView element, you can use a label, or textbox or whatever you want to show your content inside. Then create an outlet for that element. And then manipulate the HTML Code String by following way:
var urlContentArray = urlContent?.componentSeparatedByString("<span class=\"storybyline\">") // In your website (vikinglogue.com) your author name is inside this span element.
println(urlContentArray[1]) // This will print everything after that span section in your console
var authorArray = urlContentArray[1].componentSeparatedByString("</span>")
var author = authorArray[0]
Now you have the author name and you can show it in any textbox or label or in any element that support text. You can grab all other info from that page in the same way. I hope it helped.
Since RSS comes in a structured XML format, you can simply fetch your page's rss feed and parse the elements for the needed data. To see some how to code, you may check out mwaterfalls' Feedparser
e.g
<title>Girls softball dominating early</title>
<link>
http://vikinglogue.com/2377/sports/girls-softball-dominating-early/
</link>
<comments>
http://vikinglogue.com/2377/sports/girls-softball-dominating-early/#comments
</comments>
<pubDate>Wed, 22 Apr 2015 21:54:32 +0000</pubDate>

ms-webview src property points to "local-stream:///" not "ms-appdata:///"

I have some code that loads an html file in a ms-webview within a Windows 8 store app (winJS) and I'm having an issue checking the URL src of the ms-webview. Basically, the user is able to navigate within the local html files, but I want to detect when they are back on the "home" screen...
var home = "ms-appdata://local/somefile.html";
myWebView.addEventListener("MSWebViewContentLoading", function(e) {
console.log(myWebView.src); // something like: ms-local-stream://[app_key]/somefile.html
console.log(e.uri); // same as above
if (myWebView.src === home) {
// nope...
}
});
myWebView.navigate(home);
As you can see above, the webview doesn't seem to give me a way to get the URL that I actually navigated to... Thoughts?
And yes, I could inspect the ms-local-stream URL path for the file I'm looking for, but surely there's a way to get the URL that was navigate to from the webview??

Info Window URL needs to be prefixed with http NOT the default https

I am using the following code in the fusion tables 'customize info window' to create hyperlinked URL's from a column in my table:
"{URL}"
This works fine in returning the clickable hyperlink in the info box except fusion maps by default tacks on https: instead of http: when the link is clicked. This causes problems when the user clicks the hyperlink and it tries to take them to a secure site when in fact it is not secure. The browsers throw up all sorts of warnings that will scare the pants off a lot of users who don't know what is happening.
Does anybody know how to remedy this and have the default be http and not the current https?
Thanks, Shep
You may want to abandon the "{URL}" approach and display the hyperlink with some simple HTML. This example from Google shows how to modify the info window's HTML in Javascript:
google.maps.event.addListener(layer, 'click', function(e) {
// Change the content of the InfoWindow
e.infoWindowHtml = e.row['Store Name'].value + "<br>";
// If the delivery == yes, add content to the window
if (e.row['delivery'].value == 'yes') {
e.infoWindowHtml += "Delivers!";
}
});
Changing the e.row['Store Name'] to your URL column name (maybe, e.row['URL']) and surrounding by a couple of hyperlink tags <a> should do the trick:
e.infoWindowHtml = "<a href='" + e.row['URL'].value + "'>Click here!</a>";
There are three ways:
Specify a full URL including protocol in your data
Use Link here in a custom info window layout
Completely override the content as in the answer above
I would recommend #1 because you can choose the right protocol for every link. However #2 is probably easier in that you can leave your data the way it is.

Resources