I'm trying to implement my first iphone app but I'm kind a stuck. I have API which return as one of the JSON's response items HTML content (tags like p, img, em, a etc).
What is the best way to interpret HTML content on IOS? I have found basically two possible solutions:
1) UIWebView
I have try this and all content is easily loaded. But am not sure if its good way? I guess that every time user open this view all images (<img src="">) are loaded from internet (I have no control about downloading and caching images?)? Am also not sure how to style elements in webView?
2) UILabel / UITextView
I have tried this also and i can easily remove all html tags but i have no idea how to style text originally wrapped in html tags? I guess that I would have parse complete html a render it manually?
I would be really glad for every advice because I'm not sure what is the right way to continue.
Thank you.
Look up String manipulation in Swift. It's a very basic way of managing web content but it will give you great control. However i really don't recommend using an API that return html response because "Parsing" it will be very resource(CPU,RAM) consuming. Try an API with JSON response. Also if you want to cache. look up kingfisher framework.it's really efficient!
After some research I think that the right way is to use UIWebView. Because UILabel can interpret only basic HTML markup and I get more complicated HTML code like youtube embeds etc.
You can load easily HTML string using UIWebView's method loadHTMLString.
HTML content can be styled using local css. You can get path to local css file using:
NSBundle.mainBundle().URLForResource("myCssFile", withExtension: "css")
If you have local path to css you can add it to html header as usual.
If anybody know better way how to do this i still would be glad for any ideas.
Related
Currently my Nuxt.js application serves HTML pages defined in layouts, pages, routes and components.
Is it possible to render one single route / one page as a standard JSON Response? Is that possible? I mean do not render the HTML e.g. Tags - only pure JSON!
What I already tried:
Created a completely clean layout (with basically only in it), no succcess, still HTML.
Used <pre>{{jsonObject}}</pre> hoping to get plain JSON, no success.
Would be VERY happy, if somebody could tell me whether this is possible AT ALL or not?
What you're looking for here, is an API.
Vue.js will render a template (compiled to render functions, generating a DOM tree) at the end, because it's aimed towards a frontend usage. If you want to render something like an API response with pure JSON, you need to look into Express or alike.
I need to be able to build an html page and then save the rendered html output to an image. Before I switched to Go, I was accomplishing this with NodeJS and PhantomJS by building a "headless" webpage and capturing the image with a screenshot into an image file. I need to be able to do the same thing in Go. I know how to build the HTML template using the html/template package. But, I am lost on how I get essentially capture a screenshot of the rendered HTML and save it to an image with a specified width and height. This was fairly easy in PhantomJS by just calling the 'Render' method and passing the location of the image to save to. But, I can't find anyway to do this in Go.
Any help is greatly appreciated!
I am running a node.js server, and it is rendering a web page wonderfully. When I look at this in a browser, it runs exactly as I expect.
However, what I actually want to do is make the call to fully generate the html page - exactly as it is in the browser - within the node.js code, as a call. Currently, I have tried this:
http.request("http://localhost:8000/").end();
(with a few variants). This does exactly what it says, which is to make the single call to the server for the page - what it doesn't do is actually render the page, pulling in all of the other script files, and running the code on the page.
I have tried exploring express and ejs, and I think I need to use one of these, but I cannot find out how to do this fairly straightforward task. All it needs is to render an html page, but it seems to be a whole lot more complex than it should be.
What output do you want? A string of HTML? Maybe you want PhantomJS the headless browser. You could use it to render the page, then get the rendered DOM as a string of HTML.
Use the Mikeal's Request module to make http requests once you captured the response you then can inspect the html however you like.
To make that easier though you should use cheerio, this will give you a jQuery style api to manipulate the html.
Perhaps you are looking for wkhtmltopdf?
In a nutshell, it will render an entire web page (including images and JavaScript) to a PDF document.
I'm using UIWebView to display data from my organization data (publicize and legal), however, for instance, I would only want to pull specific data from the html file rather than pulling the whole URL. e.g. I want to pull the "News" section of the html and I want the user to only stay in that page, not enabling them to go into other parts of the website (e.g. home page, contact us) and allowing them to view the PDF article on the HTML file.
I've asked around and read up on DOM and screen scraping, but it seem that the data pulled are stored in a database instead.
Is there any way that I can pull just the HTML "News" section with the PDF URL into my customized HTML file and that it will be updated live (maybe every 30second it will refresh and pull information from the website so that the content and list of PDF are up to date)(e.g. added in 3new article into the main website, my customize HTML file will also refresh and pull information from website and update my article list)
If anyone can point to me a specific method that allow HTML to HTML data passing (live), that will be great and I can go do more research on it. Currently very lost and confuse as it is my first time doing this. Any help/feedback will be very much appreciated :)
EDIT: For example, google map or google search. I don't want to use the whole google webpage, just taking the important thing that i want like the search result or map display.
This will involve quite a lot of learning on your part - you'll have to learn HTML / the DOM / JavaScript and iOS/UIWebVIew.
Lets leave the live refresh part for now, I'll post another answer or edit to that later on.
That's not going to easy either (check out my earlier posting today on background execution issues that will affect you, unless the update is only to take place in the foreground
iOS Run Code Once a Day)
You will have to do something like this. And note that I've never tried this, nor seen posting of people who have on here, but in theory it should work, but there will be a lot of learning as I've said, and lots of trial and error. Its a big task when you're not familiar with these things.
1) Download the html page and load it in a UIWebView, but that UIWebView is hidden so the user's can't see it.
2) When the page has loaded its dom will be accessable.
3) You can use Javascript to access the DOM and look for the parts you want.
How you inject and run the Javascript in UIWebView can be answered in a separate question (this answer will get too long if all the exact details are included).
4) Remove the parts of the dom you are not interested in. Or use use events to make only those parts you are interested in appear, jQuery can probably help here.
5) Display the UIWebView
Alternatively the HTML could be saved to a file and string parsing could be used to search for the bits you are looking for and create a new text html file from it. I think this would get very messy, better to take advantage of the fact that UIWebView will parse the HTML page and create the dom for you.
I'm attempting to develop an application that scapes html of a site for relevant data and then display it back to the user in a more UI friendly way. I'm assuming that you can start a webView by
mWebView = (WebView) findViewById(R.id.webview);
but never setting the content to the actual view. So now my question is, can I take the html from the webview, scrape it, then somehow have the webview post back the forms, all while staying in the background? Any help is appreciated.
Or does anyone know of source such as htmlunit that will compile within android?
I have found out how to extract the HTML from the WebView using JavaScript thanks the guide on this site http://lexandera.com/category/webview_examples/ but I am still searching on how to return post forms to webView. Perhaps through javascript aswell?