This is my first attempt at a wrapper so it's a work in progress. Consider it a Beta although it isn't feature complete, I'm adding features as I require them
Not all functions and documentation implemented or tested fully yet.
Library is compatible with B4A and B4J.
1. Download jsoup 1.8.1 jar fromhttp://jsoup.org/packages/jsoup-1.8.1.jar
2. Copy the downloaded jar file from the zip to B4A or B4J libraries folder
3. Download attached jsoup library, unzip it and copy jar and xml to the libraries folder
4. Have a read of http://jsoup.org
Latest version : v0.15
Not all functions and documentation implemented or tested fully yet.
Library is compatible with B4A and B4J.
1. Download jsoup 1.8.1 jar fromhttp://jsoup.org/packages/jsoup-1.8.1.jar
2. Copy the downloaded jar file from the zip to B4A or B4J libraries folder
3. Download attached jsoup library, unzip it and copy jar and xml to the libraries folder
4. Have a read of http://jsoup.org
Latest version : v0.15
B4X:
' Parse a string
html = "<html><head ><title >First parse</title></head><body><p>Parsed HTML into a doc.</html>"
Log(js.parse_HTML(html))
' Parse a body fragment
html = "<div><p>Lorem ipsum.</p>"
Log(js.parse_BodyFragment(html))
' Load from URL
url = "https://www.b4x.com/"
Log(js.connect(url))
Log(js.connectXtra(url, "Mozilla", 0))
' Load from file
Log(js.parse_InputStream(File.OpenInput(File.DirAssets, "test.html"), "UTF-8", url))
' DOM methods
local_html = File.ReadString(File.DirAssets, "test.html")
Log(js.getElementByID(local_html, "name"))
DOM1 = js.getElementsByTag(local_html, "a", "")
DOM2 = js.getElementsByTag(local_html, "a", "href")
For i = 0 To DOM1.Size -1
Log(DOM1.Get(i))
Log(DOM2.Get(i))
Next
DOM3 = js.selectorElementText(local_html, "span")
For i = 0 To DOM3.Size -1
Log(DOM3.Get(i))
Next
' Selector Syntax - http://jsoup.org/cookbook/extracting-data/selector-syntax
Selector1 = js.selector(local_html, "img[src$=.png]")
For i = 0 To Selector1.Size -1
Log(Selector1.Get(i))
Next
' Extract Attributes, text & HTML
html = "<p>An <a href='http://example.com/'><b>example</b></a> link.</p>"
Extract1 = js.selectorElementText(html, "a")
Log(Extract1.Get(0))
Extract2 = js.selectorElementAttr(html, "a", "href")
Log(Extract2.Get(0))
Extract3 = js.selectorElementAttr(html, "a", "innerhtml")
Log(Extract3.Get(0))
Extract4 = js.selectorElementAttr(html, "a", "outerhtml")
Log(Extract4.Get(0))
Attachments
Last edited: