Giter Site home page Giter Site logo

scinfu / swiftsoup Goto Github PK

View Code? Open in Web Editor NEW
4.3K 4.3K 324.0 1.88 MB

SwiftSoup: Pure Swift HTML Parser, with best of DOM, CSS, and jquery (Supports Linux, iOS, Mac, tvOS, watchOS)

Home Page: https://scinfu.github.io/SwiftSoup/

License: MIT License

Ruby 0.21% Swift 99.77% C 0.02%
dom extract html html-document parse selector swift swiftsoup

swiftsoup's People

Contributors

0xtim avatar aehlke avatar aloisius avatar beerpiss avatar cendolinside123 avatar chickdan avatar danramteke avatar fassko avatar garthsnyder avatar gemiren avatar hactar avatar jeffreyca avatar kdubb avatar khaptonstall avatar lutzifer avatar magetron avatar matadan avatar mkscrg avatar mshibanami avatar muxinqi avatar paccos avatar ptrkstr avatar rlovelett avatar romanpodymov avatar roslund avatar samalone avatar scinfu avatar siuying avatar snq-2001 avatar valentinperignon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiftsoup's Issues

Dynamic library linker warning

When building an extension that uses SwiftSoup I get a linker warning:

ld: warning: linking against a dylib which is not safe for use in application extensions: /Users/.../Carthage/Build/iOS/SwiftSoup.framework/SwiftSoup

How can I joined '\n' with the .text() ?

eg: let html: String = "

One one

<span style="color:#333333;font-family:"font-size:16px;background-color:#FFFFFF;">Two two
<span style="color:#333333;font-family:"font-size:16px;background-color:#FFFFFF;"> Three three
<span style="color:#333333;font-family:"font-size:16px;background-color:#FFFFFF;"> Four four"
let doc: Document = try SwiftSoup.parse(html)
return try doc.text()
Then, I want to joined '\n' with eath text, like this "One one \n Two two \n Three three..."
How can I do with it ? Thank you for your reply.

Parser don't work when string has 0 notes

public static func parseBodyFragment(_ bodyHtml: String, _ baseUri: String)throws->Document {
		let doc: Document = Document.createShell(baseUri)
		if let body: Element = doc.body() {
			let nodeList: Array<Node> = try parseFragment(bodyHtml, body, baseUri)
			//var nodes: [Node] = nodeList.toArray(Node[nodeList.size()]) // the node list gets modified when re-parented
            if nodeList.count > 0 {
            for i in 1..<nodeList.count{
				try nodeList[i].remove()
			}
			for node: Node in nodeList {
				try body.appendChild(node)
			}
            }
		}
		return doc
	}

I have added nodeList.count for that.

Is it possible to use SwiftSoup from Obj-C?

I'm working on a legacy project that mixes Obj-C and Swift code, and want to replace string matching with SwiftSoup.

I'm pulling in SwiftSoup as a dependency with CocoaPods, and can use it from Swift without issue. Is there a way I can use SwiftSoup in the Obj-C code as well?

Does not build with SPM

The CleanerTest file is outside of the SwiftSoupTests directory meaning that it cannot be used with Swift Package Manager.

Carthage Build Fails for Mac Platform

I added this to my Cartfile:

github "scinfu/SwiftSoup"

And then did this:

carthage update --platform mac

And it failed with:

*** Skipped building SwiftSoup due to the error:
Dependency "SwiftSoup" has no shared framework schemes for any of the platforms: Mac

Any suggestions? Thanks! :)

Could not cast value of type 'Swift.Optional<SwiftSoup.Element>'

I am randomly downloading html pages and using SwiftSoup to parse them (1.6.0)

The odd page just gives me the following

Could not cast value of type 'Swift.Optional<SwiftSoup.Element>' (0x103049718) to 'SwiftSoup.Element' (0x100b4ded0).
2018-02-15 19:21:05.242422+0000 burf[42885:2056856] Could not cast value of type 'Swift.Optional<SwiftSoup.Element>' (0x103049718) to 'SwiftSoup.Element' (0x100b4ded0).

HTML page url "http://policewb.gov.in/"

Seems to be something in

func replaceActiveFormattingElement(_ out: Element, _ input: Element)throws {
        try formattingElements = replaceInQueue(formattingElements as! Array<Element>, out, input)//todo: testare as! non è bello
    }

Is there anyway I can handle this issue without it killing my program

Leading blank space after parsing

Lib version: 1.4.2
Swift 3
iPhone 7 - iOS 10.3

We have the following HTML where after parsing add an extra leading blank space.

HTML:
<html><body><div>\r\n<div dir=\"ltr\">\r\n<div id=\"divtagdefaultwrapper\"><font face=\"Calibri,Helvetica,sans-serif\" size=\"3\" color=\"black\"><span style=\"font-size:12pt;\" id=\"divtagdefaultwrapper\">\r\n<div style=\"margin-top:0;margin-bottom:0;\">&nbsp;TEST</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\">TEST</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\">TEST</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\"><br>\r\n\r\n</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\">TEST</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\">TEST</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\">TEST</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\"><br>\r\n\r\n</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\"><br>\r\n\r\n</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\">TEST</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\">TEST</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\">TEST</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\"><br>\r\n\r\n</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\"><br>\r\n\r\n</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\"><br>\r\n\r\n</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\"><br>\r\n\r\n</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\"><br>\r\n\r\n</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\"><br>\r\n\r\n</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\"><br>\r\n\r\n</div>\r\n<div style=\"margin-top:0;margin-bottom:0;\">TEST</div>\r\n</span></font></div>\r\n</div>\r\n</div>\r\n</body></html>

Code to parse:
let doc: Document = try SwiftSoup.parse(contentHtml)
var text = try doc.text()

After parsing:
"TEST\r\n TEST\r\n TEST\r\n \r\n\r\n\r\n TEST\r\n TEST\r\n TEST\r\n \r\n\r\n\r\n \r\n\r\n\r\n TEST\r\n TEST\r\n TEST\r\n \r\n\r\n\r\n \r\n\r\n\r\n \r\n\r\n\r\n \r\n\r\n\r\n \r\n\r\n\r\n \r\n\r\n\r\n \r\n\r\n\r\n TEST"

'substring(with:)' is deprecated: Please use String slicing subscript. (Swift 4)

There are some errors in the new Xcode 9 (Swift 4) for String.swift file, that can be solved easily (I've commented the old code..) :

func indexOf(_ substring: String, _ offset: Int ) -> Int {
        if(offset > characters.count) {return -1}

        let maxIndex = self.characters.count - substring.characters.count
        if(maxIndex >= 0) {
            for index in offset...maxIndex {
                let rangeSubstring = self.characters.index(self.startIndex, offsetBy: index)..<self.characters.index(self.startIndex, offsetBy: index + substring.characters.count)
                if self[rangeSubstring] == substring {
                //if self.substring(with: rangeSubstring) == substring {
                    return index
                }
            }
        }
        return -1
    }

and:

static func split(_ value: String, _ offset: Int, _ count: Int) -> String {
        let start = value.index(value.startIndex, offsetBy: offset)
        let end = value.index(value.startIndex, offsetBy: count+offset)
        let range = start..<end
        //return value.substring(with: range)
        return String(value[range])
    }

outerHTML() will add spaces and new lines wrongly

(the answer of issue #26 cannot solve my problem)
Hi, when I use parse() method to parse a html file, and then write the dom outer html to a new file, it will contain wrong spaces. For example, in the raw html, it has:
<div><p>a<p></div>

but in outerHtml():

<div>
    <p>
         a
    </p>
</div>

in this case, the position of 'a' change when render the html page.

Is there any method or solution to solve this problem?

Get all text nodes?

How can I get all text nodes in a document, process/change the text and get the resulting document?

Memory leak

SwiftSoup seems to have some leaked objects (Attributes, Document, Tag etc.), when I use it.

Is this due to the library or my implementation?

Change Log

Hello! Your framework is popular enough to start logging all changes! This is my favourite Change Log as example. Thanks in advance!

Example for inlining style for email HTML

I have a use case that involves reading a single-file HTML with <style> tags, and inlining the styles in the body's included tags. This would be for email HTML, where classes are not usually allowed, but inline styles are.

What is the iOS minimum version to support and what architecture?

I receive an error while making release saying the below message:
Undefined symbols for architecture armv7:
"_FE9SwiftSoupScG9AmpersandSc", referenced from:
function signature specialization <Arg[0] = Owned To Guaranteed> of SwiftSoup.TokeniserState.read (SwiftSoup.Tokeniser, SwiftSoup.CharacterReader) throws -> () in TokeniserState.o
"_FE9SwiftSoupScG8LessThanSc", referenced from:
function signature specialization <Arg[0] = Owned To Guaranteed> of SwiftSoup.TokeniserState.read (SwiftSoup.Tokeniser, SwiftSoup.CharacterReader) throws -> () in TokeniserState.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

(debug works fine but only getting release generates the error)

Parse process never finished for real we sites

Example:

import Just
import SwiftSoup

let url: String = "http://comcast.net"
let response: HTTPResult = Just.get(url)
let data: Data = response.content
let html = String(data: data!, encoding: String.Encoding.utf8)

do {
let doc: Document = try SwiftSoup.parse(html!)
print(try doc.text())
}
catch {
print("Error")
}

It never prints anything, just runs forever

How to manage SwiftSoup by Carthage? It builds failed.

SwiftSoup scheme builds well in the project.
However , when I try to manage it in Carthage , it builds failed .

I'am no sure which cause this error , the project itself or the Carthage?

Following is some of the the error message logged by Carthage, I hope you can give me some suggestion.

Xcode 8.2.1 (8C1002)
Swift 3.0.2
Carthage 0.23
SwiftSoup tag 1.4.2

Undefined symbols for architecture arm64:
  "_FE9SwiftSoupScG9AmpersandSc", referenced from:
      function signature specialization <Arg[0] = Owned To Guaranteed> of SwiftSoup.TokeniserState.read (SwiftSoup.Tokeniser, SwiftSoup.CharacterReader) throws -> () in TokeniserState.o
  "_FE9SwiftSoupScG10BackslashFSc", referenced from:
      function signature specialization <Arg[0] = Owned To Guaranteed> of SwiftSoup.TokeniserState.read (SwiftSoup.Tokeniser, SwiftSoup.CharacterReader) throws -> () in TokeniserState.o
  "_FE9SwiftSoupScG8LessThanSc", referenced from:
      function signature specialization <Arg[0] = Owned To Guaranteed> of SwiftSoup.TokeniserState.read (SwiftSoup.Tokeniser, SwiftSoup.CharacterReader) throws -> () in TokeniserState.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Ld /Users/umisky/Library/Caches/org.carthage.CarthageKit/DerivedData/SwiftSoup/1.2.9/Build/Intermediates/SwiftSoup.build/Release-iphoneos/SwiftSoup.build/Objects-normal/armv7/SwiftSoup normal armv7
    cd /Users/umisky/Desktop/Reimu/Carthage/Checkouts/SwiftSoup
    export IPHONEOS_DEPLOYMENT_TARGET=9.0
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch armv7 -dynamiclib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.2.sdk -L/Users/umisky/Library/Caches/org.carthage.CarthageKit/DerivedData/SwiftSoup/1.2.9/Build/Products/Release-iphoneos -F/Users/umisky/Library/Caches/org.carthage.CarthageKit/DerivedData/SwiftSoup/1.2.9/Build/Products/Release-iphoneos -filelist /Users/umisky/Library/Caches/org.carthage.CarthageKit/DerivedData/SwiftSoup/1.2.9/Build/Intermediates/SwiftSoup.build/Release-iphoneos/SwiftSoup.build/Objects-normal/armv7/SwiftSoup.LinkFileList -install_name @rpath/SwiftSoup.framework/SwiftSoup -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -miphoneos-version-min=9.0 -dead_strip -Xlinker -object_path_lto -Xlinker /Users/umisky/Library/Caches/org.carthage.CarthageKit/DerivedData/SwiftSoup/1.2.9/Build/Intermediates/SwiftSoup.build/Release-iphoneos/SwiftSoup.build/Objects-normal/armv7/SwiftSoup_lto.o -fembed-bitcode -Xlinker -bitcode_verify -Xlinker -bitcode_hide_symbols -Xlinker -bitcode_symbol_map -Xlinker /Users/umisky/Library/Caches/org.carthage.CarthageKit/DerivedData/SwiftSoup/1.2.9/Build/Products/Release-iphoneos -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos -Xlinker -add_ast_path -Xlinker /Users/umisky/Library/Caches/org.carthage.CarthageKit/DerivedData/SwiftSoup/1.2.9/Build/Intermediates/SwiftSoup.build/Release-iphoneos/SwiftSoup.build/Objects-normal/armv7/SwiftSoup.swiftmodule -single_module -compatibility_version 1 -current_version 1 -Xlinker -dependency_info -Xlinker /Users/umisky/Library/Caches/org.carthage.CarthageKit/DerivedData/SwiftSoup/1.2.9/Build/Intermediates/SwiftSoup.build/Release-iphoneos/SwiftSoup.build/Objects-normal/armv7/SwiftSoup_dependency_info.dat -o /Users/umisky/Library/Caches/org.carthage.CarthageKit/DerivedData/SwiftSoup/1.2.9/Build/Intermediates/SwiftSoup.build/Release-iphoneos/SwiftSoup.build/Objects-normal/armv7/SwiftSoup
Undefined symbols for architecture armv7:
  "_FE9SwiftSoupScG9AmpersandSc", referenced from:
      function signature specialization <Arg[0] = Owned To Guaranteed> of SwiftSoup.TokeniserState.read (SwiftSoup.Tokeniser, SwiftSoup.CharacterReader) throws -> () in TokeniserState.o
  "_FE9SwiftSoupScG8LessThanSc", referenced from:
      function signature specialization <Arg[0] = Owned To Guaranteed> of SwiftSoup.TokeniserState.read (SwiftSoup.Tokeniser, SwiftSoup.CharacterReader) throws -> () in TokeniserState.o
ld: symbol(s) not found for architecture armv7

** BUILD FAILED **


The following build commands failed:
	Ld /Users/umisky/Library/Caches/org.carthage.CarthageKit/DerivedData/SwiftSoup/1.2.9/Build/Intermediates/SwiftSoup.build/Release-iphoneos/SwiftSoup.build/Objects-normal/arm64/SwiftSoup normal arm64
(1 failure)

Question regarding SwiftSoup.parse(_:_:)

@param baseUri The URL where the HTML was retrieved from. Used to resolve relative URLs to absolute URLs, that occur before the HTML declares a <base href> tag.

Is this parameter intended to resolve the value of any href tag into an absolute URL?

Thai language characters

Thai language is not displaying properly in UIWebview.  We are running the html string through SwiftSoup, and the resulting string is manipulating the Thai characters.  Here is the test example I've created:

"<br>\r\n<br>\r\n<font size=\"2\" face=\"sans-serif\">Lorem Ipsum บังคับ Amet นั่ง, consectetur adipiscing Elit Maecenas หุบเขาญี่ปุ่นเพียงอย่างเดียว ตอนนี้เวลาที่จะลงทุนโปรตีน เสียงนุ่มของสมาชิกในการไว้ทุกข์ VespaCam หุบเขากล่อง การเชื่อมโยงเว็บไซต์ Semper ใน ประสิทธิภาพการทำงานของเส้นผ่าศูนย์กลางใด ๆ แต่การดูแลผู้เล่นฟุตบอลสำนักฟุตบอลสมาร์ทและเรียงลำดับความต้องการ สดนำไปหักลดหย่อนเส้นผ่าศูนย์กลาง ID Ut Libero แต่ละช่วงเวลา lorem ถั่วลิสงได้บังคับ แต่ dui ราคา malesuada แต่ละเครือข่ายแครอทวันหยุดสุดสัปดาห์ ไม่มีน้ำซุปหรือซอส ullamcorper ullamcorper กลัวใครใหญ่กว่าลูกศรสารต้านอนุมูลอิสระ</font>"

We then take this string and run it through SwiftSoup.parse using this code:

let originalDocument = try SwiftSoup.parse(testString.replacingOccurrences(of: "\r\n", with: "\n"))

This is the result output:

Document <html><head></head><body><br> <br> <font size="2" face="sans-serif">Lorem Ipsum บงคบ Amet นง, consectetur adipiscing Elit Maecenas หบเขาญปนเพยงอยางเดยว ตอนนเวลาทจะลงทนโปรตน เสยงนมของสมาชกในการไวทกข VespaCam หบเขากลอง การเชอมโยงเวบไซต Semper ใน ประสทธภาพการทงานของเสนผาศนยกลางใด ๆ แตการดแลผเลนฟตบอลสนกฟตบอลสมารทและเรยงลดบความตองการ สดนไปหกลดหยอนเสนผาศนยกลาง ID Ut Libero แตละชวงเวลา lorem ถวลสงไดบงคบ แต dui ราคา malesuada แตละเครอขายแครอทวนหยดสดสปดาห ไมมนซปหรอซอส ullamcorper ullamcorper กลวใครใหญกวาลกศรสารตานอนมลอสระ</font></body>
</html>

SwiftSoup.parse(_:_:) fails to correctly parse this iframe

<iframe src=\"https://www.googletagmanager.com/ns.html?id=GTM-M48W9J\"\n\t\t                  height=\"0\" width=\"0\" style=\"display:none;visibility:hidden\"></iframe>

Here are its attributes:

[
    "src": SwiftSoup.Attribute,
    "": SwiftSoup.BooleanAttribute,
    "height": SwiftSoup.Attribute,
    "width": SwiftSoup.Attribute,
    "style": SwiftSoup.Attribute
 ]

It crashes in ParseSettings.normalizeAttributes() on this line:

try attr.setKey(key: attr.getKey().lowercased())

because attr.getKey() is empty.

Code to reproduce:

SwiftSoup.parse(html, "https://9to5mac.com")

Parser parseBodyFragment memory leak

Hi,
It is parsing the HTML correctly but when I was debugging the Application and it looks like Parser has a memory leak.
It is reflecting leak on Parser.parseBodyFragment line . Please check the screenshot.

screen shot 2017-06-26 at 2 25 03 am

Linux Swift 3.1 Build Failing

SwiftSoup does not build on Linux with Swift 3.1 due to Apple helpfully renaming RegularExpression to NSRegularExpression on Linux in 3.1... I have no idea why either! I'll get a PR together which sorts this out and updates the CI scripts to run on 3.1 across everything

Sample code throws error

When trying to use the following sample code:

do{
let html = "<title>First parse</title>"
+ "

Parsed HTML into a doc.

"
let doc: Document = try SwiftSoup.parse(html)
return try doc.text()
}catch Exception.Error(let type, let message){
print(message)
}catch{
print("error")
}

Xcode returns the following error on the return try line:
Unexpected non-void return value in void function

Example_ not working

Hello
Thanks for the project well i run pod install on example_ and after i run the project nothing appears how can i try it plz help?

How to implement this Jsoup code in Swiftsoup?

How to implement this Jsoup code in Swiftsoup?

String URL = "http://www.example.com";
String USER_AGENT = "mozilla";
Response res;
Document doc;
						
res=Jsoup.connect(URL).userAgent(USER_AGENT)
		.timeout(15000)
		.data("id_bab", id_bab)
		.method(Method.POST)
                .followRedirects(true)
		.ignoreContentType(true)
                .execute();
						
	if(res.statusCode() == 200){	
		doc = res.parse();
	}

How to get rid of new line symbol generated by `try html()`

Hello! I have a string:

hello<span class='smile'>TT</span>ios<span class='smile'>QQ</span>world

And I want to transform it to 5 custom objects:

[TheString, TheSmile, TheString, TheSmile, TheString]

This way I get an Element from the string:

let element = try SwiftSoup.parse(string).body()!

Most of the time I do the parsing recursively, so I don't know the initial html string which constructed the Element, but I have found the way to get this string:

let initialHtmlString = try html()

And I got this:

hello\n<span class='smile'>TT</span>ios\n<span class='smile'>QQ</span>world

Then I take each child's try outerHtml() and cut it out from the string. In the end I got 5 objects:

TheString = hello\n
TheSmile = TT
TheString = ios\n
TheSmile = QQ
TheString = world

The problem is: 'try html()' adds new line symbol which affects the final result. Is there a way to get the result without undesired new line symbols?

Thanks

int has no member multipliedReportingOverflow

I am seeing this error anywhere this method is used throughout swiftsoup.

just for sake of being thourough this error began after installing tesseract and running the pod update function.

I removed tesseract and reinstalled and the error was still occuring

I opened a new project

ran pod init
added swifsoup and set package to version 10.3
ran pod install
opened new workspace
attempted to build blank project with just swift soup and am still recieving the same errors

I have completely reinstalled cocoapods, I have cleared my caches, I have attempted to clean the cache however non of this has helped.

if this is user error I am sorry

SwiftSoup in Xcode 9

Hi there,

I can't import SwiftSoup into my Xcode 9 project.
When typing in "import SwiftSoup" I get the following error: "No such module 'SwiftSoup' and 34 other compiler errors...

Is it planned to update SwiftSoup for Xcode 9? Any time plan when its ready?

Missing canned Whitelist

I tried using your code sample in my project.

do{
    let unsafe: String = "<p><a href='http://example.com/' onclick='stealCookies()'>Link</a></p>"
    let safe: String = try SwiftSoup.clean(unsafe, Whitelist.basic())!
    // now: <p><a href="http://example.com/" rel="nofollow">Link</a></p>
}catch Exception.Error(let type, let message){
    print(message)
}catch{
    print("error")
}

There's an error: Type 'Whitelist' has no member 'basic'. SwiftSoup.Whitelist.basic() also isn't defined.

Looks like there should be Whitelist with some pre-canned rules: https://jsoup.org/apidocs/org/jsoup/safety/Whitelist.html

Convert Document back to HTML string?

The README needs a code example of how to get the entire Document instance and generate the full HTML of it back into a String including html, head, body sections. In the interim, how do I do it? the html() method seems to remove the head. I'm trying to sanitize html then load it into a WKWebView. Perhaps the clean method is removing it?

            let str = try doc.html()
            let html = "<html>\(str)</html>"
            
            let wl:Whitelist = try Whitelist.relaxed().addEnforcedAttribute("a", "rel", "nofollow")
            let safe: String = try SwiftSoup.clean(html, wl)!  // the output starts with a div tag instead of html!

Extract video links from html ?

First thanks for great library .
I'd like to extract video files from html documents , like by searching for .mp4 or something , how to do this with swiftsoup ?

Add newer simulators to targeted devices to build with Carthage

  • tvOS
  • watchOS

Otherwise can't update with Carthage

» carthage update --platform watchOS
*** Fetching SwiftSoup
*** Checking out SwiftSoup at "1.6.2"
*** xcodebuild output can be found in /var/folders/wl/qnr2g12d0_b8gt90wzr0hlq40000gn/T/carthage-xcodebuild.NSZJeb.log
*** Building scheme "SwiftSoup-watchOS" in SwiftSoup.xcodeproj
Build Failed
	Task failed with exit code 70:
	/usr/bin/xcrun xcodebuild -project /Users/kristaps/Documents/ios/TartuWeatherProvider/Carthage/Checkouts/SwiftSoup/SwiftSoup.xcodeproj -scheme SwiftSoup-watchOS -configuration Release -derivedDataPath /Users/kristaps/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/SwiftSoup/1.6.2 -sdk watchsimulator -destination platform=watchOS\ Simulator,id=5AE2A1D5-AF63-4E0B-BD98-E549C495F9AE -destination-timeout 3 ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES build (launched in /Users/kristaps/Documents/ios/TartuWeatherProvider/Carthage/Checkouts/SwiftSoup)

This usually indicates that project itself failed to compile. Please check the xcodebuild log for more details: /var/folders/wl/qnr2g12d0_b8gt90wzr0hlq40000gn/T/carthage-xcodebuild.NSZJeb.log

Shell Script Invocation Error

/Users/alex/Library/Developer/Xcode/DerivedData/Forecast-fwijjcxzzzlsqafojqsrnnuecwpm/Build/Products/Debug-iphoneos/Forecast.app/Frameworks/SwiftSoup.framework: unknown error -1=ffffffffffffffff
Command /bin/sh failed with exit code 1

Running on Iphone 5(IOS 10.0)
All other devices on IOS 11+ works correctly

CPU is high

thank you html parser , it's a very smart tool like jsoup. but i found when i use it , the cpu is very high.

I compare it with other tool base on libxml2 (like Fuzi, kanna).i test in my project , fuzzy and kanna use 10%-15% cpu when parse one web site, but swiftsoup is 60% and more.

but I like this project because of liking jsoup too.

How can I get the checked state of an input?

Hello,

if I have some HTML:

How can I determine if the input is checked or not? I've tried checking if the element has the attribute "checked" but that doesn't work, and when I print out all the attributes, checked isn't in the list.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.