使用jmeter从HTML源代码中提取值

时间:2016-01-28 03:09:55

标签: html regex jmeter

我知道它可能是重复但我无法从此HTML源中提取值。任何帮助将不胜感激。

所以我要做的是从页面获取项目的pid。 正在从csv文件中读取项目的名称,我需要获取pid。

例如,如果这里的项目是“AA项目”,也可以使用项目密钥“AA”,需要提取的pid是 10441

由于这些值不是标签,我无法弄清楚如何提取它们。

更新:只需使用pid =(\ d ....)即可获得所有pid,而不会引用任何项目名称或密钥。

 <table id="project-list" class="aui">
        <thead>
            <tr>
                <th></th>
                <th>Name</th>
                <th>Key</th>

                    <th class="project-list-type">Project Type</th>

                <th>URL</th>
                <th>Project Lead</th>
                <th>Default Assignee</th>
                <th>Operations</th>
            </tr>
        </thead>
        <tbody>

                <tr data-project-key="AA">
                    <td class="cell-type-icon" data-cell-type="avatar">
                        <div class="aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar"><span class="aui-avatar-inner"><img src="/secure/projectavatar?pid=10441&amp;amp;avatarId=10011&amp;amp;size=small" alt="Project Avatar for 10441" /></span></div>
                    </td>
                    <td data-cell-type="name">
                        <a id="view-project-10441" href="/plugins/servlet/project-config/AA/summary">AA project</a>
                    </td>
                    <td data-cell-type="key">AA</td>


                            <span>Software</span>
                        </td>

                    <td class="cell-type-url" data-cell-type="url">

                            No URL


                    </td>
                    <td class="cell-type-user" data-cell-type="lead">

                            <a class="user-hover" rel="localadmin" id="view_AA_projects_localadmin" href="/secure/ViewProfile.jspa?name=localadmin">Atlassian Administrator</a>


                    </td>
                    <td class="cell-type-user" data-cell-type="default-assignee">

                        Unassigned

                    </td>
                    <td data-cell-type="operations">
                        <ul class="operations-list">

                            <li><a class="edit-project" id="edit-project-10441" href="/secure/project/EditProject!default.jspa?pid=10441&amp;returnUrl=ViewProjects.jspa">Edit</a></li>


                            <li><a id="change_project_type_10441" class="change-project-type-link" data-project-id="10441" href="#">Change project type</a></li>


                            <li><a id="delete_project_10441" href="/secure/project/DeleteProject!default.jspa?pid=10441&amp;returnUrl=ViewProjects.jspa">Delete</a></li>

                        </ul>
                    </td>
                </tr>

                <tr data-project-key="AAL">
                    <td class="cell-type-icon" data-cell-type="avatar">
                        <div class="aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar"><span class="aui-avatar-inner"><img src="/secure/projectavatar?pid=10442&amp;amp;avatarId=10011&amp;amp;size=small" alt="Project Avatar for 10442" /></span></div>
                    </td>
                    <td data-cell-type="name">
                        <a id="view-project-10442" href="/plugins/servlet/project-config/AAL/summary">AAL project</a>
                    </td>
                    <td data-cell-type="key">AAL</td>

                        <td class="cell-type-project-type">

                            <span>Software</span>
                        </td>

                    <td class="cell-type-url" data-cell-type="url">

                            No URL


                    </td>
                    <td class="cell-type-user" data-cell-type="lead">

                            <a class="user-hover" rel="localadmin" id="view_AAL_projects_localadmin" href="/secure/ViewProfile.jspa?name=localadmin">Atlassian Administrator</a>


                    </td>
                    <td class="cell-type-user" data-cell-type="default-assignee">

                        Unassigned

                    </td>
                    <td data-cell-type="operations">
                        <ul class="operations-list">

1 个答案:

答案 0 :(得分:0)

我不建议使用正则表达式来解析HTML数据,因为开发和维护会很困难,而且对标记更改非常敏感,因此非常脆弱,有关详细信息,请参阅https://stackoverflow.com/a/1732454/2897748

转而使用XPath Extractor,相关配置为:

  • 参考名称:任何有意义的内容,即//JasperPrint is already filled HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse(); httpServletResponse.setContentType("application/csv; charset=cp1252"); httpServletResponse.setCharacterEncoding("cp1252"); httpServletResponse.addHeader("Content-disposition", "attachment; filename=nameoffile.csv"); httpServletResponse.addHeader("Content-type", "application/csv; charset="+Charset.forName("utf-8").displayName()); ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream(); JRCsvExporter exporter = new JRCsvExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "cp1252"); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, servletOutputStream); exporter.setParameter(JRCsvExporterParameter.CHARACTER_ENCODING, "cp1252"); exporter.setParameter(JRCsvExporterParameter.FIELD_DELIMITER, ";");
  • XPath查询:def super_sum(*args): total = 0 args = list(args) if len(args) == 1: args = args[0] for d in args: if isinstance(d, list): total += super_sum(d) else: total += d return total print super_sum([1, 2, [3, 4], 5], 3, [2, 3])
  • 如果您的回复不符合XHTML,请检查id

演示:

XPath Extractor Demo

参考文献: