首页 > 编程知识 正文

php获得页面元素,html获取php数据

时间:2023-12-27 22:26:40 阅读:324702 作者:FGBD

本文目录一览:

自动化测试中怎么获取frame页面上的元素

frame存在两种:嵌套,非嵌套

根据元素id或index切换frame:driver.switch_to.frame()

切换到默认frame:driver.switch_to.default_content()

切换到父级frame:driver.switch_to.parent_frame()

切到frame页:

1.处理未嵌套的frame:

driver.switch_to_frame("frame的id")

driver.switch_to_frame("frame-index")frame无ID时依据索引来处理,索引从0开始driver.switch_to_frame(0)

2.处理嵌套frame:

对于嵌套的先进入到iframe的父节点,再进到子节点,然后可以对子节点里面的对象进行处理和操作

driver.switch_to.frame("父节点")

driver.switch_to.frame("子节点")

switch_to.parent_frame()

switch_to.default_content()

测试页面:

以获取frame页面元素为例:

php获取指定网页内容

一、用file_get_contents函数,以post方式获取url

?php

$url= '';

$data= array('foo'= 'bar');

$data= http_build_query($data);

$opts= array(

'http'= array(

'method'= 'POST',

'header'="Content-type: application/x-www-form-urlencodedrn"  .

"Content-Length: "  . strlen($data) . "rn",

'content'= $data

)

);

$ctx= stream_context_create($opts);

$html= @file_get_contents($url,'',$ctx);

二、用file_get_contents以get方式获取内容

?php

$url='';

$html= file_get_contents($url);

echo$html;

?

三、用fopen打开url, 以get方式获取内容

?php

$fp= fopen($url,'r');

$header= stream_get_meta_data($fp);//获取报头信息

while(!feof($fp)) {

$result.= fgets($fp, 1024);

}

echo"url header: {$header} br":

echo"url body: $result";

fclose($fp);

?

四、用fopen打开url, 以post方式获取内容

?php

$data= array('foo2'= 'bar2','foo3'='bar3');

$data= http_build_query($data);

$opts= array(

'http'= array(

'method'= 'POST',

'header'="Content-type: application/x-www-form-

urlencodedrnCookie:cook1=c3;cook2=c4rn"  .

"Content-Length: "  . strlen($data) . "rn",

'content'= $data

)

);

$context= stream_context_create($opts);

$html= fopen(';id2=i4','rb',false, $context);

$w=fread($html,1024);

echo$w;

?

五、使用curl库,使用curl库之前,可能需要查看一下php.ini是否已经打开了curl扩展

?php

$ch= curl_init();

$timeout= 5;

curl_setopt ($ch, CURLOPT_URL, '');

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

$file_contents= curl_exec($ch);

curl_close($ch);

echo$file_contents;

?

用PHP如何获取网页审查元素中的内容?

使用file_get_contents可以获取网页源码

?php

$homepage  =  file_get_contents ( '' );

echo  $homepage ;

  ?

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。