Application not pulling contents from web page

Hello everyone,

I am currently working on an application for my fathers business. I have built parts of the app in other languages before decided to use Swift. The problem I am having with Swift is that when I try to pull the information I need from his website not all the information is coming through. Only half of the text from the page is getting sent to the application.

The page only contains text which I am going to parse through to display information. So the code below should be able to pull the text from the page. I'm not quite sure why it's not pulling all of the text.

Code:

Summary

if let web = URL(string: url) {
do {
let content = try String(contentsOf: web);
return content;
} catch {
print("[ERROR] Web page could not be loaded (URL: (url))");
}

I have tried different styles of encoding but still, the same problem with only a portion of the text is getting to the app. If anyone has any tips or has had this issue before please let me know how you solved it.

Thank you

This seems like a question for StackOverflow, as this forum is mainly for questions about using the Swift language itself, not Apple’s APIs. You’ll probably have better luck over there.

Generally, though, websites are increasingly complex beasts and they may not load all of their content all at once. Additional resources may need to be loaded or async JavaScript may call for additional data. So you should investigate where the rest of the content you expect is really coming from. Ultimately, though, it usually requires a full browser engine to scrape websites nowadays.

Thank you for the tip. I was unaware that this site wasn't for help with API's. I will head over there and see if I can find anything.

If you don’t mind not using Swift, you might consider using Selenium WebDriver for interacting with websites. I am a fan.