【问题标题】:Finding possible URL parameters查找可能的 URL 参数
【发布时间】:2019-09-19 19:31:29
【问题描述】:

我正在尝试用 Ruby/Mechanize 编写一个网络爬虫。我试图实现的一件事是一个可以找到潜在 URL 参数的函数。这是一个sn-p:

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_parameters('http://example.com/') =&gt; ['baz']

【问题讨论】:

  • 注意:require 中的文件名几乎总是小写。这可能适用于不区分大小写的文件系统,但会在区分大小写的文件系统上中断。
  • ^ 已记录并修复
  • 不,不可能。如果页面没有以任何方式记录其参数,您就无法找出它们是什么。

标签: php ruby mechanize


【解决方案1】:

你可以调整字符串:

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

【讨论】:

  • 嗯?这里的参数在 url 中已经了。无需加载页面,只需解析 url 字符串即可。
  • 有可能 www.example.com 在加载时返回 www.example.com?baz=123,至少我是这样理解的。
  • 提供的 php 示例不会这样做。问题是如何找到那些“隐藏”的参数?
猜你喜欢
  • 2017-07-23
  • 2014-12-25
  • 2014-06-03
  • 1970-01-01
  • 2021-02-06
  • 2020-10-07
  • 2021-12-29
  • 2013-03-30
  • 2014-12-24
相关资源
最近更新 更多