简体   繁体   English

Objective-C:HTML网站

[英]Objective-C: HTML Websites

I was told to retrieve data from this website on traffic in Sao Paolo, Brazil: 我被告知从巴西圣保罗的交通网站上检索数据:

http://www.cetsp.com.br http://www.cetsp.com.br

I have to retrieve information which is displayed all over the place, including other links/parts of the site. 我必须检索在整个地方显示的信息,包括网站的其他链接/部分。 Im not so sure how. 我不太确定如何。 I have to parse HTML and have found a tutorial which does so, but it does not teach me how to parse this website, or any other in particular. 我必须解析HTML并找到了这样做的教程,但它没有教会我如何解析这个网站,或者任何其他特别的网站。

If you go to that website you will see four squares saying North, South, East West and the KM of their traffic or something, I have to gather that data and information. 如果你去那个网站你会看到四个广场说北,南,东西和他们的交通的KM,我必须收集这些数据和信息。 But how !? 但是如何!? And also, I have to get the map image of traffic from this site: 而且,我必须从这个站点获取流量的地图图像:

http://www.cetsp.com.br/transito-agora/leste/mapa-de-fluidez.aspx http://www.cetsp.com.br/transito-agora/leste/mapa-de-fluidez.aspx

Again, but how? 再说一次,怎么样? I have the HTML parsing classes hpple. 我有HTML解析类hpple。 Here is the code I know so far: 这是我目前所知的代码:

NSURL *tutorialsUrl = [NSURL URLWithString:@"http://www.cetsp.com.br"];
NSData *tutorialsHtmlData = [NSData dataWithContentsOfURL:tutorialsUrl];

TFHpple *tutorialsParser = [TFHpple hppleWithHTMLData:tutorialsHtmlData];

So I'm really boggled on how to even start on this. 所以我真的很难过如何开始这个。 If anyone could help me, that would be great! 如果有人能帮助我,那就太好了!

For every piece of data you want, you're going to need to write some code to retrieve that data from the document tree in the HTML. 对于您想要的每个数据,您将需要编写一些代码来从HTML中的文档树中检索该数据。

The first step is to open the site in Safari/Chrome's web inspector and get a feel for where in the tree the data you want is. 第一步是在Safari / Chrome的Web检查器中打开该站点,并了解树中所需数据的位置。

Next, you'll want to write code to navigate to that point in the document tree and pull that data out. 接下来,您将要编写代码以导航到文档树中的该点并将该数据拉出。 Whenever I've had to do something like this I've been spoiled by being able to use a language like python that has a lot of modules available to accomplish this. 每当我不得不做这样的事情时,我就会被使用像python这样的语言所破坏,这种语言有很多模块可用来完成这个任务。 I'm not super familiar with what Cocoa has available in this area, but have a look at: 我不太熟悉Cocoa在这个领域的可用性,但看看:

http://www.raywenderlich.com/14172/how-to-parse-html-on-ios http://www.raywenderlich.com/14172/how-to-parse-html-on-ios

Ray has provided a pretty good worked example that should get you up and running. Ray提供了一个非常好的工作示例,可以帮助您启动并运行。 Perhaps you've already seen this article, in which case you're well on your way. 也许你已经看过这篇文章,在这种情况下你很顺利。 You just need to find your paths thru the document to the elements you need. 您只需要找到通过文档到您需要的元素的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM