Php 查找可能的URL参数

Php 查找可能的URL参数,php,ruby,mechanize,Php,Ruby,Mechanize,我正在尝试用Ruby/Mechanize编写一个web scraper。我试图实现的一件事是一个可以找到潜在URL参数的函数。下面是一个片段: require 'mechanize' def find_parameters(url) mechanize = Mechanize.new result = [] # build list of potential parameters at URL result # return end 想象一下发送并传递URLht

我正在尝试用Ruby/Mechanize编写一个web scraper。我试图实现的一件事是一个可以找到潜在URL参数的函数。下面是一个片段:

require 'mechanize'
def find_parameters(url)
    mechanize = Mechanize.new
    result = []
    # build list of potential parameters at URL
    result # return
end
想象一下发送并传递URL
http://example.com/
。在
example.com
上有一个
index.php
文件,它接收URL参数调用
baz
,并将该参数的值打印到页面上

<?php
    if (isset($_GET['baz'])) {
        echo $_GET['baz'];
    }
?>

因此
http://example.com?baz=123
将转到打印
123
的页面。通过查看源代码我们知道,
baz
是一个潜在的参数,有没有办法让Mechanize找到所有潜在的参数并返回它们的列表


例如:
find_参数('http://example.com/')=>['baz']

您可以调整字符串:

require 'mechanize'
def find_parameters(url)
  mechanize = Mechanize.new
  result = []
  mechanize.get(url)  #go to the page
  # get the current page, split in the possible parameters list, split by parameters
  # (rescue in case there are no params)
  ( mechanize.page.uri.to_s.split("?")[1].split("&") rescue []).each do |key_val| 
    # split the pair of param and value, and store the param name
    result << key_val.split("=")[0]
  end
  return result
end
要求“机械化”
def find_参数(url)
mechanize=mechanize.new
结果=[]
机械化。获取(url)#转到页面
#获取当前页面,在可能的参数列表中拆分,按参数拆分
#(无参数时的救援)
(mechanize.page.uri.to_.s.split(“?”[1])。split(“&”)rescue[])。每个都做
#拆分参数和值对,并存储参数名称

结果说明:
require
中的文件名几乎总是小写。这可能适用于不区分大小写的文件系统,但在区分大小写的文件系统上会中断。^注意并修复了,不可能。如果页面没有以任何方式记录其参数,您就无法找到它们是什么。嗯?这里的参数已经在url中。无需加载页面,只需解析url字符串。加载时,www.example.com可能返回www.example.com?baz=123,至少我是这样解释的。提供的php示例不会这样做。问题是如何找到这些“隐藏”参数?