I have a question about how to scratch the link and title of the web page from the iOS app.

Asked 2 years ago, Updated 2 years ago, 29 views

I want to create an app that scratches the title of the article and its link on online news sites such as Blotter and Non-Sexcess and shows it to users.

However, no matter how much I searched on the Internet, I couldn't find a way to scan the contents of the website regularly (every time an article is updated) and make it visible on the iOS app.

Please let me know if there is a method, function, library, etc. that can be used in this case. Thank you.

rss ios swift

2022-09-22 22:05

2 Answers

(1) Not regularly, but how to scratch and show articles every time you turn on the app

You can take the html from the url you want as shown in the code below and check if there is a new article.

if let url = NSURL(string: "https://www.bloter.net") {
    do {
        let contents = try NSString(contentsOfURL: url, usedEncoding: nil)
        Analyze print(content)//content to extract links to new articles.
    } } catch {
        // // contents could not be loaded
    }
} } else {
    // // the URL was bad!
}

Source

You can parse and write the HTML file that you read. Looking at the main page html of the blotter, the article is tied with the tag article as shown below, so it won't be difficult to parse.

<article class="latestPost most-popular excerpt " itemscope="" itemtype="http://schema.org/BlogPosting"></article>

But scratch an article came suddenly in my article from sites that could change the structure html. 기사를 읽어오는 로직이 모두 앱에 들어있다면 어느날 갑자기 그 앱이 동작하지 않게 되는 문제가 생깁니다. Especially a commercial app ios is subject to inspection because users to deploy at least a few days the app makes Jack a dull a problem. So I need separate server.

(2) How to configure a separate server

You can configure a separate server and regularly check for new articles there to prepare the data in advance. It has the advantage of always being able to deliver data to the app in a fixed format. And even if the HTML composition of the site you want to read changes, it can be immediately reflected in the server and changed.

The downside is that you need to try to configure the servers separately. There are too many options for how to create a server, depending on your preferred language/framework. If you're curious about this, please ask us a separate question.


2022-09-22 22:05

The method of importing html as it is should be the last choice.

Blogging or breaking to some extent? The site provides rss feed. It's a fixed link, and it's in xml format, so once you open it, it's a structure that you can understand, and you can almost continue to use it

Non-access also provides links like http://kr.besuccess.com/feed/. If you approach this url using the code above and analyze the xml, you will get the desired result.


2022-09-22 22:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.