Questions tagged [swiftsoup]

a Swift HTML Parser library for working with real-world HTML through a convenient API for extracting and manipulating data using DOM, CSS, and jquery-like methods.

SwiftSoup is a pure Swift HTML Parser library for working with real-world HTML. It provides a convenient API for extracting and manipulating data, using the best of DOM, CSS, and jquery-like methods. SwiftSoup implements the WHATWG HTML5 specification, parsing HTML to the same DOM as modern browsers do.

Main features:

  • Scrape and parse HTML from a URL, file, or string
  • Find and extract data, using DOM traversal or CSS selectors
  • Manipulate HTML elements, attributes, and text
  • Sanitizing: Clean user-submitted content against a white-list, to prevent XSS attacks
  • Deal with all varieties of HTML found in the wild; from validating to invalid tag-soup
  • Output tidy HTML

SwiftSoup is available through CocoaPods, Carthage, and on GitHub.

For further information and documentation see

Author: Nabil Chatbi, scinfu@gmail.com
Note: SwiftSoup was ported to Swift from Java Jsoup library.

License: SwiftSoup is available under the MIT license.

53 questions
0
votes
2 answers

Where is my mistakes while I m using completion handler with multiple url?

I have many URLs that I have to scrape from the website. After I get them from my bundle file I create an array that includes many URLs. I passed this array my function which is called scrapeSanatcilar and I add completion handler there but…
portable
  • 11
  • 3
0
votes
1 answer

How can I get list elements with web scraping?

I need to get list elements with web scraping. I can't reach elements one by one, I can get all elements in one string. How can I get list elements using SwiftSoup or any other option? Here my function: …
mehmett
  • 111
  • 1
  • 12
0
votes
1 answer

How to get text from element without whitespace normalization and trimmed using SwiftSoup in swift

I want to get exact text without whitespace normalisation and trim using SwiftSoup library. Currently, SwiftSoup provide element.text() method to extract text from that element. But text()- Method gives trimmed and whitespace normalised text. Any…
Dhanraja
  • 211
  • 2
  • 13
0
votes
1 answer

Swiftsoup parsing is not finding all HTML classes

I have a method to parse website with using Swiftsoup go get the price of a product: @objc func actionButtonTapped(){ let url =…
Chris
  • 1,828
  • 6
  • 40
  • 108
0
votes
1 answer

Scrape product price from any Website using Swift Soup

Inside my app I would like to scrape the price of any product (user types in the wanted URL). I searched quite a bit now and I found out that there are couple of Webscrapers, I think I will use SwiftSoup for now. However I couldn't find a single…
Chris
  • 1,828
  • 6
  • 40
  • 108
0
votes
1 answer

Can't correctly use try doc.getElementsByClass("h4 font-weight-bold mb-0 ") in SWIFT

I need to scrape the third html div, given the class. I have this code that scrape the first element, but I can't figure it out how to scrape only the third element let countryDiv: Element = try doc.getElementsByClass("h4 font-weight-bold mb-0…
0
votes
1 answer

how to filter a string in swift and get the middle result

I am trying to do web scraping since the author of the website does not provide an API but he wanted me to do an App for the website. The website is about getting a time table for the day. So the print values that I get are these. 1: module Kevin…
Max
  • 11
  • 2
0
votes
0 answers

Replace Text within HTML-Tags, except within HTML-Attributes (regular expression)

I'm trying to find some text regex matches in a HTML string and replace that matches with a special markup. In the example string below, I would like to find the word swiftsoup, and replace it with swiftsoup, but exclude all matches in all…
SchmidtFx
  • 498
  • 4
  • 16
0
votes
1 answer

How to parse the specific content in the HTML to my App

I'm trying to parse data from a website to my own application. I manage to get the html and print the html using AlamoFire but I don't know how am I going to get the specific data from that html file. Here I get the HTML and I'm trying to get the…
Met Boz
  • 3
  • 2
0
votes
1 answer

getting the ingredients info out of tesco HTML Xcode Swift4

I am using swiftsoup! i am trying to copy this info so i can look form ingredients

Sugar, Cocoa Mass, Cocoa Butter, Dried Skimmed Milk, Dried Whey (from Milk), Vegetable…

0
votes
1 answer

Swift, Reach multiple classes with SwiftSoup for parsing HTML file

I am parsing a HTML site. (using swiftsoup cocoapods) I reached the data with classes by getElementByClass method. struct OddResponse { let odds: [Odd] init(_ innerHTML: Any?) throws { guard let htmlString = innerHTML as? String else { throw …
sashatheitguy
  • 77
  • 1
  • 8
0
votes
1 answer

how to retrieve label from a HTML class in a table using Swift

Trying to retrieve: "17,02" from the HTML below:
Shift
  • 43
  • 9
0
votes
1 answer

How to handle swift classes having same name?

I am using swiftsoup library , in that there is Document class And I have used this to parse html documents. But in my team one of my friend created Document class for diffrent purpose.Now it is conflicting for my code after taking his pull.Is there…
blackstorm
  • 60
  • 10
0
votes
3 answers

SwiftSoup cocoapods install only and only version 1.4, not 1.5

I tried to install swiftSoup to parse HTML to my xCode project but unfortunately version of swiftSoup installed by command expressed in official site is 1.4 which is unacceptable to work with swift 4.0. I found out that version of swiftSoup…
Ninja
  • 309
  • 7
  • 26
0
votes
1 answer

Trying to do deal with errors and optionals the right way

I am attempting to use SwiftSoup to scrape some HTML. This example, based on the SwiftSoup github documentation, works fine… func scrape() throws { do { let htmlFromSomeSource = "

HerpDerp

Eric_WVGG
  • 2,957
  • 3
  • 28
  • 29