首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单击表中没有ID和A标签的第一个单元格

单击表中没有ID和A标签的第一个单元格
EN

Stack Overflow用户
提问于 2019-01-28 07:12:56
回答 2查看 150关注 0票数 0

我尝试单击表的第一个单元格,该单元格没有ID和A标记。单击第一个单元格后,系统会提示我下载一个zip文件。然后,我将解压压缩文件并将解压的csv文件导入到MySQL表中。除了单击第一个单元格之外,我已经完成了所有工作。我只需要帮助点击第一个单元格来下载文件。请帮帮忙。

这是表格的截图:

https://imgur.com/a/PUR1y1t

表头

代码语言:javascript
复制
<table class="htCore">
<colgroup>
  <col class="rowHeader" style="width: 50px;">
  <col style="width: 90px;">
  <col style="width: 147px;">
  <col style="width: 144px;">
  <col style="width: 208px;">
  <col style="width: 512px;">
</colgroup>
<thead>
  <tr>
     <th class="" style="height: 25px;">
        <div class="relative"><span class="colHeader cornerHeader">&nbsp;</span></div>
     </th>
     <th class="">
        <div class="relative"><span class="colHeader columnSorting">Operation</span></div>
     </th>
     <th class="">
        <div class="relative"><span class="colHeader columnSorting">Requested ID</span></div>
     </th>
     <th class="ht__highlight">
        <div class="relative"><span class="colHeader columnSorting">Requested Date</span></div>
     </th>
     <th class="ht__highlight">
        <div class="relative"><span class="colHeader columnSorting">Status</span></div>
     </th>
     <th class="ht__highlight">
        <div class="relative"><span class="colHeader columnSorting">RequestInfo</span></div>
     </th>
  </tr>
</thead>

身体

代码语言:javascript
复制
<tbody>
      <tr>
     <th class="ht__highlight ListView_Current">
        <div class="relative"><span class="rowHeader">1</span></div>
     </th>
     <td class="htDimmed ListView_Current">M/R</td>
     <td class="htDimmed ListView_Current">20190127220652968</td>
     <td class="htDimmed highlight">01/27/2019 22:06:52</td>
     <td class="htDimmed highlight">Completed</td>
     <td class="htDimmed highlight">(FileName,DNBCC_MGMR_20190127220652968.zip),(FileSize,721234),(SiteName,Atlantic, Tomorrows Office),(Depot Name,),(CSV Separator,,),(Download to,Your PC),(CSV Type,Detail),(Search Range(MM/DD/YYYY),01/21/2019-01/27/2019),(Customer,),(Device S/N,),(Vendor,)</td>
      </tr>
      <tr>
     <th class="">
        <div class="relative"><span class="rowHeader">2</span></div>
     </th>
     <td class="htDimmed">M/R</td>
     <td class="htDimmed">20190127220158966</td>
     <td class="htDimmed">01/27/2019 22:01:58</td>
     <td class="htDimmed">Completed</td>
     <td class="htDimmed">(FileName,DNBCC_MGMR_20190127220158966.zip),(FileSize,721249),(SiteName,Atlantic, Tomorrows Office),(Depot Name,),(CSV Separator,,),(Download to,Your PC),(CSV Type,Detail),(Search Range(MM/DD/YYYY),01/21/2019-01/27/2019),(Customer,),(Device S/N,),(Vendor,)</td>
      </tr>
      <tr>
     <th class="">
        <div class="relative"><span class="rowHeader">3</span></div>
     </th>
     <td class="htDimmed">M/R</td>
     <td class="htDimmed">20190127215611964</td>
     <td class="htDimmed">01/27/2019 21:56:11</td>
     <td class="htDimmed">Completed</td>
     <td class="htDimmed">(FileName,DNBCC_MGMR_20190127215611964.zip),(FileSize,721257),(SiteName,Atlantic, Tomorrows Office),(Depot Name,),(CSV Separator,,),(Download to,Your PC),(CSV Type,Detail),(Search Range(MM/DD/YYYY),01/21/2019-01/27/2019),(Customer,),(Device S/N,),(Vendor,)</td>
  </tr>

</tbody>
</table>

我尝试了以下操作,但得到一个System.Windows.Forms.HtmlElement.InnerText.get返回nothing错误:

代码语言:javascript
复制
Dim tables As HtmlElementCollection = 
 WebBrowser1.Document.GetElementsByTagName("div") - also "table"
    For Each tbl As HtmlElement In tables
        For Each row As HtmlElement In tbl.All
            For Each cell As HtmlElement In row.All
                If Not cell.Style Is Nothing Then
                    If cell.InnerText.Contains("M/R") Then - also tried InnerHtml
                        cell.InvokeMember("click") 
                    End If
                End If
            Next
        Next
    Next

还有javascript:

代码语言:javascript
复制
function downloadFile(fileName, fileSize) {
var downloadForm = $('<form 
action="https://ssd.support.thewebsite.com/atremotecenter/DL" method="get">
<input type="text" name="Content-Type" value="application/x-www-form-urlencoded; charset=UTF-8"/><input type="text" name="Accept-Encoding" value="gzip"/>
<input type="text" name="X-NRS-User-ID" value="myusername"/><input type="text" name="X-NRS-Certificate" value="iHmkmuotsGXfYF/VVp8U5l5YT68pNywANPF7Hk1FH8zUyWPFWPdQ7LwCyJcubSjhDegily9s+CgO5r+ip8aWZnuqeyWKYG2uXnb0KXgV8To0sxmCHIjNPedSBgzHUNK0W5eZeoeUP02w8TpBoPsF4g=="/>
<input type="text" name="X-NRS-File-Name" value="'+fileName+'"/> . 
<input type="text" name="Range" value="bytes=0-'+(fileSize-1)+'"/> . 
</form>').hide().appendTo('body');
downloadForm.submit();
downloadForm.remove();
return false;
}
EN

回答 2

Stack Overflow用户

发布于 2019-01-28 11:07:58

我希望这就是你要找的。您需要在Windows窗体上放置一个need浏览器控件。

在您的调用表单/事件中,输入以下代码来帮助设置set浏览器:

代码语言:javascript
复制
    'WebBrowser1.ObjectForScripting = [.NET object]  
    WebBrowser1.ScriptErrorsSuppressed = True
    WebBrowser1.AllowNavigation = True

然后,调用Then浏览器的导航函数:

代码语言:javascript
复制
    WebBrowser1.Navigate("http://www.example.com")  

最后,在Webbrowser1.documentCompleted事件中放入以下内容:

代码语言:javascript
复制
    Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        Dim strFileName As String
        Dim lngFileSize As Long

        'You will still need to get this information from the html contents of the table.
        strFileName = "DNBCC_MGMR_20190127215611964.zip"
        lngFileSize = 721257

        WebBrowser1.Document.InvokeScript("downloadFile", {strFileName, lngFileSize})
    End Sub
票数 1
EN

Stack Overflow用户

发布于 2019-01-28 14:41:02

因为您的表已经设置了它的class属性,所以您可以使用它来标识它。然后,只需要在其中获得第一个<tbody>和第一个<tr>

代码语言:javascript
复制
'Iterate all elements with the "htCore" class.
For Each htCore As HtmlElement In WebBrowser1.Document.GetElementsByClassName("htCore")
    'Check if the element is a table.
    If htCore.TagName.Equals("table", StringComparison.OrdinalIgnoreCase) Then

        'Get all <tbody> elements in the table.
        Dim tbodies As HtmlElementCollection = htCore.GetElementsByTagName("tbody")
        If tbodies.Count > 0 Then

            'Get all <tr> elements in the first body.
            Dim rows As HtmlElementCollection = tbodies(0).GetElementsByTagName("tr")
            If rows.Count > 0 Then
                'Invoke click on the first row.
                rows(0).InvokeMember("click")
                Exit For 'Stop looping.
            End If

        End If

    End If
Next
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54393779

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档