Merge pull request #226 from SNQ-2001/master

fix readme
This commit is contained in:
Nabil Chatbi 2022-07-22 13:15:24 +02:00 committed by GitHub
commit 574006f80d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 13 deletions

View File

@ -107,16 +107,16 @@ After parsing a document, and finding some elements, you'll want to get at the d
```swift
do {
let html: String = "<p>An <a href='http://example.com/'><b>example</b></a> link.</p>";
let html: String = "<p>An <a href='http://example.com/'><b>example</b></a> link.</p>"
let doc: Document = try SwiftSoup.parse(html)
let link: Element = try doc.select("a").first()!
let text: String = try doc.body()!.text(); // "An example link"
let linkHref: String = try link.attr("href"); // "http://example.com/"
let linkText: String = try link.text(); // "example""
let text: String = try doc.body()!.text() // "An example link."
let linkHref: String = try link.attr("href") // "http://example.com/"
let linkText: String = try link.text() // "example"
let linkOuterH: String = try link.outerHtml(); // "<a href="http://example.com"><b>example</b></a>"
let linkInnerH: String = try link.html(); // "<b>example</b>"
let linkOuterH: String = try link.outerHtml() // "<a href="http://example.com/"><b>example</b></a>"
let linkInnerH: String = try link.html() // "<b>example</b>"
} catch Exception.Error(let type, let message) {
print(message)
} catch {
@ -258,7 +258,7 @@ Like the other methods in `Element`, the attr methods return the current `Elemen
```swift
do {
try doc.select("div.masthead").attr("title", "swiftsoup").addClass("round-box");
try doc.select("div.masthead").attr("title", "swiftsoup").addClass("round-box")
} catch Exception.Error(let type, let message) {
print(message)
} catch {
@ -275,7 +275,7 @@ Use the HTML setter methods in `Element`:
```swift
do {
let doc: Document = try SwiftSoup.parse("<div>One</div><span>One</span>")
let div: Element = try doc.select("div").first()! // <div></div>
let div: Element = try doc.select("div").first()! // <div>One</div>
try div.html("<p>lorem ipsum</p>") // <div><p>lorem ipsum</p></div>
try div.prepend("<p>First</p>")
try div.append("<p>Last</p>")
@ -285,7 +285,7 @@ do {
let span: Element = try doc.select("span").first()! // <span>One</span>
try span.wrap("<li><a href='http://example.com/'></a></li>")
print(doc)
// now: <li><a href="http://example.com/"><span>One</span></a></li>
// now: <html><head></head><body><div><p>First</p><p>lorem ipsum</p><p>Last</p></div><li><a href="http://example.com/"><span>One</span></a></li></body></html>
} catch Exception.Error(let type, let message) {
print(message)
} catch {
@ -312,7 +312,7 @@ Use the text setter methods of `Element`:
```swift
do {
let doc: Document = try SwiftSoup.parse("")
let doc: Document = try SwiftSoup.parse("<div></div>")
let div: Element = try doc.select("div").first()! // <div></div>
try div.text("five > four") // <div>five &gt; four</div>
try div.prepend("First ")
@ -516,9 +516,9 @@ print(txt)
```swift
let xml = "<?xml version='1' encoding='UTF-8' something='else'?><val>One</val>"
guard let doc = try? SwiftSoup.parse(xml, "", Parser.xmlParser()) else { return }
guard let element = try? doc.getElementsByTag("val").first() // Find first element
element.text("NewValue") // Edit Value
let valueString = element.text() // "NewValue"
guard let element = try? doc.getElementsByTag("val").first() else { return } // Find first element
try element.text("NewValue") // Edit Value
let valueString = try element.text() // "NewValue"
```
## How to get all `<img src>`