Page 1 of 1

Get value from div

Posted: Sun Oct 06, 2019 11:42 pm
by seodream
I want to get the value from the div and store it in a variable.
Here is the html code:

Code: Select all

<div>Your login: admin<br></div>
<div>Your password: gge12jdj<br></div>
I'm need to get text "admin" and "gge12jdj".

Re: Get value from div

Posted: Mon Oct 07, 2019 2:03 am
by support
php example:

Code: Select all

// get div inner html by element inner text "Your login"
$login = $div->get_inner_html_by_attribute("innerText", "Your login", false);
// get div inner html by element inner text "Your password"
$password = $div->get_inner_html_by_attribute("innerText", "Your password", false);

// $login contains "Your login: admin<br>";
// $password contains "Your password: gge12jdj<br>";

// get login and password values using function get_string
echo $login=get_string($login,'Your login:','<br>');
echo "<br>";
echo $password=get_string($password,'Your password:','<br>');

// get string by prefix
function get_string($str1, $pr1, $pr2, &$ind_st = 0)
{
	// get start index
	$ind1 = strpos($str1, $pr1, $ind_st);
	if($ind1 === false)
	{
		return "";
	}
	$ind1_1 = $ind1 + strlen($pr1);

	// get last index
	$ind2 = strpos($str1, $pr2, $ind1_1);
	if ($ind2 === false)
	{
		return "";
	}
	// get substring by prefix
	$sres = substr($str1, $ind1 + strlen($pr1), $ind2 - $ind1_1);
	return trim($sres); 
}

Re: Get value from div

Posted: Mon Oct 07, 2019 1:20 pm
by kojon
If div in frame it would work?

Re: Get value from div

Posted: Mon Oct 07, 2019 4:22 pm
by support
If div in frame then:

Code: Select all

// get div inner html by element inner text "Your login"
$login = $div->get_inner_html_by_attribute("innerText", "Your login", false,$frame_num);
// get div inner html by element inner text "Your password"
$password = $div->get_inner_html_by_attribute("innerText", "Your password", false,$frame_num);
where $frame_num is a frame number (0 or 1 or 2 etc).