mirror of
https://github.com/jlengrand/OpenGraphKt.git
synced 2026-03-10 08:31:23 +00:00
Compare commits
2 Commits
renovate/a
...
feat/multi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
873f104789 | ||
|
|
765210d667 |
@@ -12,7 +12,9 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.jsoup:jsoup:1.20.1")
|
||||
implementation("com.fleeksoft.ksoup:ksoup:0.2.4")
|
||||
implementation("com.fleeksoft.ksoup:ksoup-kotlinx:0.2.4")
|
||||
implementation("com.fleeksoft.ksoup:ksoup-network:0.2.4")
|
||||
implementation(project(":opengraphkt"))
|
||||
testImplementation(kotlin("test"))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package fr.lengrand.opengraphkt
|
||||
|
||||
import org.jsoup.Jsoup
|
||||
import com.fleeksoft.ksoup.Ksoup
|
||||
import java.io.File
|
||||
import java.net.URI
|
||||
|
||||
@@ -25,7 +25,7 @@ fun main() {
|
||||
println("\nExample 2: Parsing from File")
|
||||
try {
|
||||
val resourceUrl = object {}.javaClass.getResource("/example.html")
|
||||
val resourceFile = File(resourceUrl.toURI())
|
||||
val resourceFile = File(resourceUrl!!.toURI())
|
||||
|
||||
// Parse the file
|
||||
val openGraphData = parser.parse(resourceFile)
|
||||
@@ -66,7 +66,7 @@ fun main() {
|
||||
// Example 4: Parse Open Graph data from a Jsoup Document
|
||||
println("\nExample 4: Parsing from JSoup Document")
|
||||
|
||||
val doc = Jsoup.parse(html)
|
||||
val doc = Ksoup.parse(html)
|
||||
val openGraphDataDoc = parser.parse(doc)
|
||||
|
||||
println("Title: ${openGraphDataDoc.title}")
|
||||
|
||||
@@ -14,7 +14,9 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.jsoup:jsoup:1.20.1")
|
||||
implementation("com.fleeksoft.ksoup:ksoup:0.2.4")
|
||||
implementation("com.fleeksoft.ksoup:ksoup-kotlinx:0.2.4")
|
||||
implementation("com.fleeksoft.ksoup:ksoup-network:0.2.4")
|
||||
testImplementation(kotlin("test"))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package fr.lengrand.opengraphkt
|
||||
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.select.Elements
|
||||
import com.fleeksoft.ksoup.Ksoup
|
||||
import com.fleeksoft.ksoup.network.parseGetRequestBlocking
|
||||
import com.fleeksoft.ksoup.nodes.Document
|
||||
import com.fleeksoft.ksoup.parseFile
|
||||
import com.fleeksoft.ksoup.select.Elements
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.io.File
|
||||
import java.net.URI
|
||||
import java.net.URL
|
||||
@@ -61,21 +64,20 @@ class Parser {
|
||||
* Extracts all Open Graph tags from a URL and returns a structured Data object.
|
||||
*
|
||||
* @param url The URL to be parsed for Open Graph information.
|
||||
* @return An Data object containing all extracted Open Graph data.
|
||||
* @return A Data object containing all extracted Open Graph data.
|
||||
*/
|
||||
fun parse(url: URL) : Data {
|
||||
val doc = Jsoup.connect(url.toString()).get()
|
||||
return parse(doc)
|
||||
return parse(Ksoup.parseGetRequestBlocking(url.toString()))
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts all Open Graph tags from a raw HTML String and returns a structured Data object.
|
||||
*
|
||||
* @param html The raw HTML String to be parsed for Open Graph information.
|
||||
* @return An Data object containing all extracted Open Graph data.
|
||||
* @return A Data object containing all extracted Open Graph data.
|
||||
*/
|
||||
fun parse(html: String) : Data {
|
||||
val doc = Jsoup.parse(html)
|
||||
val doc = Ksoup.parse(html)
|
||||
return parse(doc)
|
||||
}
|
||||
|
||||
@@ -84,10 +86,12 @@ class Parser {
|
||||
*
|
||||
* @param file The file to parse
|
||||
* @param charset The charset to use for parsing (default is UTF-8)
|
||||
* @return An Data object containing all extracted Open Graph data.
|
||||
* @return A Data object containing all extracted Open Graph data.
|
||||
*/
|
||||
fun parse(file: File, charset: String = "UTF-8") : Data {
|
||||
val doc = Jsoup.parse(file, charset)
|
||||
val doc = runBlocking {
|
||||
Ksoup.parseFile(file, file.absolutePath, charset)
|
||||
}
|
||||
return parse(doc)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user