I want to read web pages (not mine and specified) and replace some words with other words in the web page loaded.
For example, let's suppose that there is a webpage that shows string "Hello, World! 07-17-2015". And I want to replace all "07" with "08". Then this page will be shown like this: "Hello, World! 08-17-2015". (There is only a string in this example, but I want to execute at any page)
I want to do this with Android. Can I make an app with this feature?
Just make a request to get the HTML content of the page (bazillions methods to do it, lots and lots of libraries, or plain HttpURLConnection).
Then take that output as String and replace what you want:
// Your network implementation
String htmlContent = response.data.replaceAll("07", "08");
Then use a WebView and load this String inside it:
webView.loadData(htmlContent, "utf-8");
Related
I am loading website for example 'http:/example.com' in WebView,
Let this page contain a element
<a class="x" href="/test1">Click here</a>
How can I get this element 'x' and its value of href from WebView.
You need something to read HTML back in your Java code, like showed in this Answer:
how to get html content from a webview?
Then when you have your HTML content, you need a parser to extract element (and data) you need.
In past i've used JSOUP to navigate the HTML and it worked really well, you can find it here https://jsoup.org/.
You could extract the class names and href value with this: (only a concept)
Document yourPage = Jsoup.parse(htmlString);
Element aElement = yourPage.select("path to a element").first();
Set<String> classNames = aElement.classNames();
String url = aElement.attr("href");
If you need help, you can read here a pretty nice intro-tutorial from JSOUP documentation
I just want to get the HTML String from my webview for that i am trying with the following code
webviewTxt.loadUrl("javascript:HTMLOUT.processHTML(document.documentElement.outerHTML);");
But i don't know how can i get this code to string. I even don't know whether this is true code to grab the HTML String or not.
In my webview i have following String
This is a test Demo
Where "test" is written in Italic and "Demo" is written in Bold So i want to get the HTML string from above code.
Above string is just an Example, The string may be anything not the same as above string each time.
If anyone is having any idea then please guide me, I already checked so many link links from SO and other google stuff but i am not able to grab the String in HTML from Webview.
I have a page I want to scrape with android, and the contents are want are located like this:
body
div#wrapper
div#mainContentArea
div#scheduleModule
div#scheduleDayView
div#scheduleDayViewScroll
div#scheduleItemContainer
div#eventContainer
div#SSPP_o090570*A*
div.eventInfo
p.eventText
span.eventInfoDefault
How can I access the span using jsoup?
If you don't want to be taken out in the streets and whipped for your transgressions, you will split up that block of text there.
Anyway, you want to find the span whose class is eventInfoDefault? Well:
Document site = Jsoup.connect("http://www.example.com");
Element span = site.select("span.eventInfoDefault").first();
//Proceed to do whatever you want with that below.
Source: http://jsoup.org/cookbook/extracting-data/selector-syntax
I have a paragraph of text with a url at the end of it. I have the text and link in the strings.xml. Is there anyway to get it to load a new Activity from the strings.xml file? I'm assuming I'll have to break up the paragraph text and link, but thought I'd check.
strings.xml:
The quick brown fox can be found at: http://thequickbrownfox.com\n more text here
I need to change the hardcoded url "http://thequickbrownfox.com" to load a screen inside my app instead of a page on the web.
strings.xml is purely an abstraction mechanism used for string lookup to facilitate multi language support etc; you cannot use it to load activities or do anything else programatically. It sounds like you are actually talking about parsing the url out of a particular paragraph stored within strings.xml and then depending on what that url is, you invoke a corresponding activity.
If this is the case then you can either parse out the url from the paragraph and respond accordingly.
OR
you can store your paragraph as one item in strings.xml and your url as another item and combine them programmatically in your code.
Either approach can be fine depending on what you are doing.
I'm new to Android programming.
I would like to know if I can load a certain part of a website into webview? The website is made from CSS. It contains headers and buttons that I do not want to be displayed into the webview. I would only like to display the contents in the website, like images and texts. Is this possible? If so, how?
Many thanks in advance!!!
You can use the public void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl) method to load a customised html, maybe your app can get the html from the site, modify it, and loadDataWithBaseUrl then.