Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Erik is an headless browser based on WebKit. An headless browser allow to run functional tests, to access and manipulate webpages using javascript.

License

NotificationsYou must be signed in to change notification settings

phimage/Erik

Repository files navigation

Join the chat at https://gitter.im/phimage/ErikLicensePlatformLanguageIssuesCocoapodCarthage compatible

Become a Patron!Buy me a coffee

Erik is aheadless browser based onWebKit and HTML parserKanna.

An headless browser allow to run functional tests, to access and manipulate webpages using javascript.

letbrowser=Erik.visit(url: url){ document, errorin    // browse HTML element, click, submit form and more}

Navigation

Go to an url

Erik.visit(url: url){ object, erroriniflet e= error{}elseiflet doc= object{        // HTML Inspection}}

How to get current url?

iflet url=Erik.currentURL{..}

For multiple browsing you can create an instance of headless browser and use same functions

letbrowser=Erik()browser.visitURL...

HTML Inspection

Search for nodes byCSS selector

forlinkin doc.querySelectorAll("a, link"){print(link.text)print(link["href"])}

Edit first input field with name "user"

iflet input= doc.querySelectorAll("input[name=\"user\"]").first{input["value"]="Eric"}

Submit a form

iflet form= doc.querySelector("form[id='search']")as?Form{    form.submit()}

Evaluate some JavaScript

letjavaScriptSource="console.log("test");"Erik.evaluate(#"\(error)")        }    }    else if let capturedValue = obj {        // do something according to result    }}

capturedValue is the content of JavaScript variableresultErikAffect this variable in your JavaScript code.

letjavaScriptSource="console.log('test'); var resultErik = 1 + 1;"

Warning about DOM change

⚠️ All action on Dom use JavaScript and do not modify the actualDocument object and its childrenElement.

You must usecurrentContent to get a refreshedDocument object

Get current content

Erik.currentContent{(obj, err)->Voidiniflet error= err{}elseiflet document= obj{       // HTML Inspection}}

Using Future

As an optional feature, you can useFuture/Promise ( Erik use frameworksBrightFutures &Result)

Example to submit a google search

leturl=NSURL(string:"https://www.google.com")!letvalue="Erik The Phantom of Opera"// visitvarfuture:Future<Document,NSError>=Erik.visitFuture(url: url)// fill input fieldfuture= future.flatMap{ document->Future<Document,NSError>iniflet input= document.querySelector("input[name='q']"){input["value"]= value}iflet form= document.querySelector("form[name=\"f\"]")as?Form{        form.submit()}returnErik.currentContentFuture()}// finally get final result as success or errorfuture.onSuccess{ documentin    // parse result}future.onFailure{ errorinprint("\(error)")}

Limitation

On iOS 9 and macOS 10.11, you need to ensure you use https://, because iOS 9 and macOS 10.11 do not like apps sending or receiving data insecurely. If this something you want to override, click here to read aboutApp Transport Security.

Links

Setup

CocoaPods is a centralized dependency manager forObjective-C and Swift. Gohereto learn more.

  1. Add the project to yourPodfile.

    use_frameworks!pod'Erik'//orspecifictargettarget:testdopod'Erik'end
  2. Runpod install and open the.xcworkspace file to launch Xcode.

Optional Future

Addpod 'Erik/Future' to yourPodfile and runpod install.

Using carthage

Carthage is a decentralized dependency manager for Objective-C and Swift.

  1. Add the project to yourCartfile.

    github "phimage/Erik"

Roadmap

  • (WIP) WKWebView screenshot (webkit view privates api?)

Why Erik?

A well known headless browser is namedPhantomJS and a very well known browser isOpera.

As a tribute I useErik, firstname of the title character from Gaston Leroux's novel Le Fantôme de l'Opéra best known to English speakers asThe Phantom of Opera

My name is also Erik. So egotistical to call a project using its firstname isn't it.

My only justification is that I was playing Metal Gear SolidV and the creator Hideo Kojima name appears over 100 times in the game. Coincidentally the full name of the game is Metal Gear SolidV : ThePhantom Pain.

License

The MIT License. See the LICENSE file for more information.

About

Erik is an headless browser based on WebKit. An headless browser allow to run functional tests, to access and manipulate webpages using javascript.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp