mirror of
https://github.com/jlengrand/OpenGraphKt.git
synced 2026-03-10 08:31:23 +00:00
Fixes #8
Starts fixing #8. Removes required dependency to JSoup for users of the library.
This commit is contained in:
@@ -1,19 +1,18 @@
|
||||
package fr.lengrand.opengraphkt
|
||||
|
||||
import java.io.File
|
||||
import java.net.URI
|
||||
|
||||
/**
|
||||
* Example demonstrating how to use the OpenGraphParser to extract Open Graph data from HTML.
|
||||
*/
|
||||
fun main() {
|
||||
val parser = OpenGraphParser()
|
||||
val fetcher = DocumentFetcher()
|
||||
|
||||
// Example 1: Parse Open Graph data from a URL
|
||||
println("Example 1: Parsing from URL")
|
||||
try {
|
||||
val document = fetcher.fromUrl("https://www.imdb.com/title/tt0068646/")
|
||||
val openGraphData = parser.parse(document)
|
||||
val openGraphData = parser.parse(URI("https://www.imdb.com/title/tt0068646/").toURL())
|
||||
|
||||
println("Title: ${openGraphData.title}")
|
||||
println("Is valid: ${openGraphData.isValid()}")
|
||||
@@ -28,8 +27,7 @@ fun main() {
|
||||
val resourceFile = File(resourceUrl.toURI())
|
||||
|
||||
// Parse the file
|
||||
val document = fetcher.fromFile(resourceFile)
|
||||
val openGraphData = parser.parse(document)
|
||||
val openGraphData = parser.parse(resourceFile)
|
||||
|
||||
println("Title: ${openGraphData.title}")
|
||||
println("Is valid: ${openGraphData.isValid()}")
|
||||
@@ -59,8 +57,7 @@ fun main() {
|
||||
</html>
|
||||
""".trimIndent()
|
||||
|
||||
val document = fetcher.fromString(html)
|
||||
val openGraphData = parser.parse(document)
|
||||
val openGraphData = parser.parse(html)
|
||||
|
||||
println("Title: ${openGraphData.title}")
|
||||
println("Is valid: ${openGraphData.isValid()}")
|
||||
|
||||
14
demo/src/main/resources/example.html
Normal file
14
demo/src/main/resources/example.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>File Example</title>
|
||||
<meta property="og:title" content="File Example Title" />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:url" content="https://example.com/file-example" />
|
||||
<meta property="og:image" content="https://example.com/file-image.jpg" />
|
||||
<meta property="og:description" content="An example of parsing from a file" />
|
||||
</head>
|
||||
<body>
|
||||
<h1>File Example</h1>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user