2017-01-11 98 views
1

如何選擇Stage One div中的文本。它有一個獨特的名稱「field-name-field-stage-one」。我想回應總結。XPath類選擇器

鏈接至網站:http://fosterinnovationculture.com/drupalc/?q=node/17

這是我到目前爲止有:

$doc = new DomDocument; 
$some_link = 'http://fosterinnovationculture.com/drupalc/?q=node/17'; 
$tagName = 'div'; 
$attrName = 'class'; 
$attrValue = 'field-name-field-stage-one'; 

$doc->validateOnParse = true; 
$doc->loadHtml(file_get_contents($some_link)); 

$xpath = new DOMXpath($doc); 
$elements = $xpath->query("/html/body//div[contains(@class,'$attrValue')]"); 

回答

0

獲取與field-item類的內部元件,並提取nodeValue值:

$elements = $xpath->query("/html/body//div[contains(@class,'$attrValue')]/div[contains(@class, 'field-item')]"); 
print_r($elements[0]->nodeValue); 

打印:

The survey results show that your organization is ‘interested’ in design-led innovation, which is stage 1 in our framework. 

‘Interested’ means that some people in the organization are noticing design contributions and the methods designers use. Some individuals are experiencing success in a few projects.  The use of design methods is ad hoc, unintentional and happening at a grass roots level. Design continues to be perceived as an added cost to the development process. As a result, there is little executive support or buy-in. 
+0

現在,如果我想將文本存儲在變量中,就像'$ stage = $ elements [0] - > nodeValue;'? – marcos

+0

@marcos yup,適合我。 – alecxe