JMeter - 从页面获取指定的链接

时间:2017-11-21 08:45:20

标签: javascript regex jmeter

我想从一个页面获取所有链接,这些链接与特定模式匹配。

我尝试使用带有正则表达式的<a[^>]* href="([^"]*)"后处理器执行此操作:GET

我检查了public function do_resize($source_file, $target_folder, $height = 128, $width = 128){ $filename = $source_file; $temp_data = explode('/',$filename); $new_filename = end($temp_data); $temp_data = explode('.', $new_filename); $ext = end($temp_data); $new_filename = $temp_data[0] . $width .'-'. $height .'.'. $ext; $source_path = $filename; $folder_path = ''; $temp_folder = explode('/',$target_folder); foreach ($temp_folder as $folder) { $folder_path .=$folder . '/'; if (!file_exists($folder_path)) { mkdir($folder_path); } } $target_path = $target_folder; if (file_exists($source_file)) //file_exists of a url returns false.It should be real file path { return $folder_path . $new_filename; } if(isset($config_manip)){ unset($config_manip); } $config_manip = array( 'image_library' => 'gd2', 'source_image' => $source_path, 'maintain_ratio' => FALSE, 'new_image' => $target_path, 'create_thumb' => TRUE, 'thumb_marker' => $width . '-'. $height, 'width' => $width, 'height' => $height ); $CI =& get_instance(); $CI->load->library('image_lib'); $CI->image_lib->initialize($config_manip); if (!$CI->image_lib->resize()) { echo $CI->image_lib->display_errors(); echo "<br>"; echo $config_manip['source_image']; } // clear // $CI->image_lib->clear(); return $folder_path . $new_filename; } 命令的响应并发现,这些链接在响应中不可见,但链接仅在浏览器中可见,当鼠标在文本时。

2 个答案:

答案 0 :(得分:1)

通常,当鼠标悬停在文本上时,属性title将用于文本

所以在你的情况下,如果标题是在href之后,你将得到以下内容(鼠标悬在文本上的第2组)

<a[^>]* href="([^"]*)" title="([^"]*)"

并更改模板以将第二个组用作$2$

答案 1 :(得分:1)

Don't use regular expressions to parse HTML data

我建议改为CSS/JQuery Extractor,相关配置如下:

  • 参考名称:任何有意义的内容,即link
  • CSS / JQuery Expression:a
  • 属性:href
  • 匹配号码:-1

JMeter CSS JQuery Extractor

您可以使用Debug SamplerView Results Tree听众组合查看所有提取的链接网址。有关详细信息,请参阅How to Use the CSS/JQuery Extractor in JMeter文章。