문제

안녕하세요 저는 Simple_HTML_DOM을 사용하여 정확한 클래스 "hello"로 모든 태그 인스턴스를 검색하고 있습니다.

foreach($html->find('.hello')as $found

위의 내용은 "Hello World"와 같은 수업을 제공하기 때문에이 작업을 수행하지 않습니다. 배열에서 올바른 요소를 계산하고 나열하는 것은 간단합니다. 그러나 변경되는 소스 HTML은 실용적이지 않습니다.

수업에 대한 정확한 용어를 찾는 방법이 있습니까?

감사

도움이 되었습니까?

해결책

이 시도:

foreach($html->find('[class=hello]') as $found)

그래도 작동하지 않으면 항상 덜 우아하지만 여전히 작동하는 접근 방식을 수행 할 수 있습니다.

foreach($html->find('.hello') as $found)
{
    if ($found->class != 'hello')
        continue;

    //do stuff here
}

제목 아래에있는 이런 종류의 것들에 대해 더 많이 찾을 수 있습니다. HTML 요소를 찾는 방법? 매뉴얼에서. 속성 선택기는 매우 강력합니다. 여기를 참조하십시오.

[attribute]           Matches elements that have the specified attribute.
[attribute=value]    Matches elements that have the specified attribute with a certain value.
[attribute!=value]  Matches elements that don't have the specified attribute with a certain value.
[attribute^=value]  Matches elements that have the specified attribute and it starts with a certain value.
[attribute$=value]  Matches elements that have the specified attribute and it ends with a certain value.
[attribute*=value]  Matches elements that have the specified attribute and it contains a certain value.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top