mirror of
https://github.com/jlengrand/OpenGraphKt.git
synced 2026-03-10 15:51:39 +00:00
Compare commits
4 Commits
feat/multi
...
v0.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91da68172f | ||
|
|
d7cef1714e | ||
|
|
9d94d22a5e | ||
|
|
3c0eed60a7 |
@@ -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}")
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -7,14 +7,16 @@ plugins {
|
||||
}
|
||||
|
||||
group = "fr.lengrand"
|
||||
version = "0.0.3-SNAPSHOT"
|
||||
version = "0.1.0"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation(platform("org.junit:junit-bom:5.10.0"))
|
||||
testImplementation(platform("org.junit:junit-bom:5.13.1"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
implementation(kotlin("stdlib-jdk8"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user