Jump to content


Photo

Need help on a script


  • Please log in to reply
3 replies to this topic

#1 curtm

curtm
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 13 March 2006 - 05:19 PM

I need help creating a script please.

I need a script where I could enter in a url, click submit, and have the script go to that url, look for "<form" and then pull out the method="xxxx" and the action="xxxxxxxxxxxxxxxxx" and all of the input name="xxxxx" and options and selects.

Basically, I want an easy way to find out where a form is being submitted to, and all the form valune names.


Can anyone help with this?

Thanks!

#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 13 March 2006 - 06:59 PM

[!--quoteo(post=354571:date=Mar 13 2006, 05:19 PM:name=curtm)--][div class=\'quotetop\']QUOTE(curtm @ Mar 13 2006, 05:19 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I need help creating a script please.

I need a script where I could enter in a url, click submit, and have the script go to that url, look for "<form" and then pull out the method="xxxx" and the action="xxxxxxxxxxxxxxxxx" and all of the input name="xxxxx" and options and selects.

Basically, I want an easy way to find out where a form is being submitted to, and all the form valune names.
Can anyone help with this?

Thanks!
[/quote]


you're asking alot in one go. there are a few things you need to look at here:
1, opening and reading the contents of a webpage into a variable.
2, regular expressions (preg_match, etc) to actually draw out the relevent info from the variable.

unless you drop it in the freelance forum, i don't think you're gonna have much luck getting someone to write the whole script for you, as it's not a simple straightforward 'get this, do that' script. give it a blast, then post any code you have when you get into problems and we'd probably be able to help you much more.

Cheers

"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 curtm

curtm
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 13 March 2006 - 09:32 PM

Here is what I have working so far...



$sFile = file_get_contents("http://www.domain.com", False);

preg_match_all("/(\<[ \\n\\r\\t]{0,}tr[^>]*\>|\<[^>]*[\\n\\r\\t]{1,}tr[^>]*\>){1}
([^<]*<([^(\/>)]*(\/[^(t>)]){0,1}(\/t[^(r>)]){0,1})*>)*
(\<[ \\n\\r\\t]{0,}\/tr[^>]*\>|\<[^>]*[\\n\\r\\t]{1,}\/tr[^>]*\>){1}/i", $sFile, $matches);


foreach ($matches as $val) {
echo "matched: " . $val[0] . "\n";
echo "part 1: " . $val[1] . "\n";
echo "part 2: " . $val[3] . "\n";
echo "part 3: " . $val[4] . "\n\n";
}


The script above prints "matched:" and "part1" .... for every <tr> on domain.com, So I am getting closer,

but I don't get the code after preg_match_all - all the <'s and >'s and \'s - how does that stuff work?


I think if I can get it to pull out everything between <form and </form> I can get the rest to work.

Thanks!

#4 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 14 March 2006 - 08:56 AM

[!--quoteo(post=354663:date=Mar 13 2006, 09:32 PM:name=curtm)--][div class=\'quotetop\']QUOTE(curtm @ Mar 13 2006, 09:32 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
but I don't get the code after preg_match_all - all the <'s and >'s and \'s - how does that stuff work?
[/quote]

haha welcome to regular expressions. i still don't fully understand them now, but all the bits you mention are patterns that will match to the information youre after. in the case of the < and </ etc, this is literally trying to match the opening and closing tags in HTML and returns the contents. as regex has certain operators that define the way a pattern is matched, a backslash (\) is used to let the parser know that the following character is literally the character you want to match, and not an operator. just like if you wanted to put an apostrophe in a string, you'd backslash it first to tell the php parser that you really want the apostrophe, and don't mean it to be the closing quote of a string:
$nameplural = 'mark's'; // will give an error

$nameplural = 'mark\'s'; // is fine

[!--quoteo(post=354663:date=Mar 13 2006, 09:32 PM:name=curtm)--][div class=\'quotetop\']QUOTE(curtm @ Mar 13 2006, 09:32 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I think if I can get it to pull out everything between <form and </form> I can get the rest to work.
Thanks!
[/quote]

well, you say that, but all you get left with when you've pulled out the bits between the form tags is a smaller version of the page you started with, which you'll then need to match INPUT and TEXTAREA and BUTTON tags, etc. without looking too heavily into the preg_match pattern you have, it appears youre very much on the right lines.
but:
$result = preg_match("/\<form\>(.*?)\<\/form\>/i", $sFile, $resultsarray);
print_r($resultsarray);

should return all the info between the form tags.

i'd personally stick with preg_match_all though and try and work it out. it aint easy, but once you've nailed it you can do some pretty tricky search and replace tasks in minimal amount of code.

Hope that helps
Cheers
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users