Get value from div

Ask questions here, report about problems.
Post Reply
seodream
Posts: 4
Joined: Mon Sep 30, 2019 7:52 pm

Get value from div

Post by seodream » Sun Oct 06, 2019 11:42 pm

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".

User avatar
support
Site Admin
Posts: 81
Joined: Fri Feb 22, 2019 3:42 pm

Re: Get value from div

Post by support » Mon Oct 07, 2019 2:03 am

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); 
}

kojon
Posts: 15
Joined: Mon Mar 25, 2019 7:53 pm

Re: Get value from div

Post by kojon » Mon Oct 07, 2019 1:20 pm

If div in frame it would work?

User avatar
support
Site Admin
Posts: 81
Joined: Fri Feb 22, 2019 3:42 pm

Re: Get value from div

Post by support » Mon Oct 07, 2019 4:22 pm

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).

Post Reply