2017-01-11 64 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