【发布时间】:2017-07-24 13:20:27
【问题描述】:
假设我有一个 HTML 页面
<p> Some text here </p>
<p> Some other text here </p>
<h1> Title 1 </h1>
<p> Another text here </p>
<p> Some random text here </p>
<h1> Title 2 </h1>
<p> Some text here </p>
<p> Some other text here </p>
<h1>..<h1>
是否可以逐个标签抓取内容的标签
if (<h1>)
then do something
if (<p>)
then do something else
对于每个标签
【问题讨论】:
-
那么你想要做的是你想要遍历所有的 html 元素并为每个元素做一些事情?
-
签出 Jsoup 库 (jsoup.org/apidocs)。它有很多方法可以帮助您完成需要的工作
-
@RandomDeveloper - 是的,我想遍历每个标签,然后应用必要的条件
-
我尝试使用 simplehtmldom.sourceforge.net ,很好地将
标签作为 $article->find('h1')->plaintext
-
可能类似于在 php 中排列的 html 标签?
标签: php html web-scraping custom-selectors