0

我是 iOS 新手。我想像这样解析 HTML 页面:

<div class="main_menu">
          <ul class="sf-menu">
            <li class="current"><a href="#" class="sifrme_active">Holiday Tours</a>
              <ul>
                <li><a href="about-holiday-tours.html">About Us</a></li>
                <li><a href="Mohammed-el-decken.html">Mohammed El Decken</a></li>
                <li><a href="Yehia-El-Decken.html">Yehia El Decken</a></li>
              </ul>
            </li>
            </li>
            <li><a href="#" class="sifrme_active">Vacation Packages</a>
              <ul>
                <li><a href="Slov-2-Spain.html">Slov2Spain</a></li>
                <li><a href="Swiss-Alps.html">Swiss Alps</a></li>
                <li><a href="fall-hike.html">Fall Hike</a></li>
                <li><a href="nile-valley.html">Nile Valley</a></li>
                <li><a href="sahlala.html">Sahlala</a></li>
                <li><a href="Safar-El-Layaly.html">Safar El Layaly</a></li>
                <li><a href="cruising-sinai.html">Cruising Sinai</a></li>
                <li><a href="siwa-oasis.html">Siwa Siwa</a></li>
                <li><a href="Silk-Road.html">Silk-Road</a></li>
                <li><a href="French-Alps.html">French Alps</a></li>
              </ul>

            </li>
     ->         <li><a href="#">Weekend Trips</a><ul>
     ->         <li><a href="hiking.html">Hiking</a></li>
     ->         <li><a href="Sandboarding.html">Sandboarding</a></li>
     ->         <li><a href="Horseriding.html">Horse Riding</a></li>
     ->         <li><a href="GoCycle.html">GoCycle</a></li>
     ->         <li><a href="Islamic-Tour.html">Islamic Tour</a></li>
              </ul>
            </li>
            <li><a href="holiday-tours-reservation.html">Reservation</a> </li>
          </ul>
        </div>
      </div>    

我想访问箭头和我无法通过 XPathQuery 获取它们的周末旅行?请问有什么帮助吗?

4

1 回答 1

0
NSArray *data = [xpath searchWithXPathQuery:@"//li//a//child::text()"];

搜索数据

for (int i = 0; i < data.count; i++) {
  TFHppleElement *element = [data objectAtIndex:i];
  NSLog(@"%@", [element content]);
}

查看里面的数据,你可以检查如何得到你想要的。

这是一个 xPath 语法教程页面: http ://www.w3schools.com/xpath/xpath_syntax.asp

于 2012-11-05T13:46:36.417 回答