我的html源代码中有以下表单标记
<form class="webform-submission-form webform-submission-add-form webform-submission-footer-subscription-form webform-submission-footer-subscription-add-form webform-submission-footer-subscription-node-7-form webform-submission-footer-subscription-node-7-add-form js-webform-details-toggle webform-details-toggle" data-drupal-selector="webform-submission-footer-subscription-node-7-add-form" action="/en/" method="post" id="webform-submission-footer-subscription-node-7-add-form" accept-charset="UTF-8">
,我想用xpath捕获action
值
这就是我尝试过的
$xpath = new DOMXpath($dom);
$link = $xpath->query('//form/a');
$link->getAttribute('action');
一无所获
答案 0 :(得分:1)
$xpath = new DOMXpath($dom);
$form = $xpath->query('//form'); // get the form (remove the "/a" you had)
$formAttribute = $form->getAttribute('action'); // your action is now stored in the $formAttribute variable