0

I am trying to export some data from an web-page and use it in the swift program by means of webkit.

My Intention: I want to use an existing web-page, that includes a drop-down selection box by means of swift.

I am trying to figure out a solution on my own in autodidactic way screening the web for a solution but finally I am stuck since several weeks now - I try using webkit and swiftsoup.

I need to access DOM and tried to get the DOM structure of the web page with

let  doc: Document = try SwiftSoup.parse(myHTMLString) 

myHTMLString is a result of getHTLM()

func getHTML(URLString: String) -> String {
            
            var myURLString = URLString
                  
             guard let myURL = URL(string: myURLString) else {
              print("Error: \(myURLString) doesn't seem to be a valid URL")
              return "invalid URL"
        
             }
                 do {
                    let myHTMLString = try String(contentsOf: myURL, encoding: .utf8)
                  //   print("HTML : \(myHTMLString)")
                    
                    return myHTMLString
                    
                 } catch let error {
                     print("Error: \(error)")
                    return "Error: \(error)"
                 }
         
        }

However, I do not have the DOM, but only the HTML code in the doc variable.

In this HTLM code,however, I cannot find the drop-down box. It looks like the original code, but I need access to the Document Object Model. Eventhough the DOM should be available this time.

Any suggestions how to access elements of the DOM ( after running JavaScripts?) - If swiftsoup is not the correct tool, maybe there is another one ?

To obtain the currently selected value, it should it work with

guard let elements = try? doc.select("[name = body.dfb-container.dfb-wrapper.frame.content.actionForm.dfb-panel.dfb-panelContent.dfb-row.kontext.seasonId]") else {return}

Even tough I don't have an error reported, seems to be something wrong with the syntax.

Can someone help me, please?

Thanks in advance for some hints how to go on !

The element structure (using e.g. development tool of safari) looks like:

"<body>"
<div id ="dfb-container">

<div id ="dfb-wrapper">

<div id ="frame">
<div id ="content">

<div id ="dfb-panel">

<form name="actionForm" method="POST" action="/spielplus/mod_sbo/webflow0.do">
    <div class="dfb-panel">
...
<div class="dfb-panelHeader">
...
<div class="dfb-panelContent">


...
<div class="dfb-row">
...
<select name="kontext.seasonId" class="dfb-element" onchange="sendEvent(this, true, true);" event="SEARCH" size="1"><option 

value="">Aktuelle Spiele</option>
<option value="20/21">20/21</option>
<option value="19/20">19/20</option>
<option value="18/19">18/19</option>
<option value="17/18">17/18</option>
<option value="16/17">16/17</option><option </select>
Pasaretti
  • 1
  • 1
  • SwiftSoup is not (capable of) fetching the content of the address you are providing. You should first fetch the content yourself, and provide that to `parse:` instead. https://stackoverflow.com/questions/26134884/how-to-get-html-source-from-url-with-swift – EDUsta Feb 22 '21 at 09:17
  • Thanks four you answer, I added some text for clarification above. My problem was not using SwiftSoup - I could parse HTML code, however I need access to elements of the DOM – Pasaretti Mar 08 '21 at 14:31

0 Answers0