[英]Python + Selenium Web scraping dynamic elements
我正在嘗試從 SEC 檔案網站中提取以下信息。
1) 大型加速申報 2) 加速申報 3) 非加速申報 4) 小型報告公司 5) 新興成長型公司
這是它在網站上的顯示方式:
Large accelerated filer ☒
Accelerated filer ☐
Non-accelerated filer ☐ (Do not check if a smaller reporting company)
Smaller reporting company ☐
Emerging growth company ☐
在某些情況下,可能不存在一項或多項。 我想編寫一個通用代碼,可以為許多公司提取這些值。 現在我面臨的問題是 HTML 的結構因公司而異。 到目前為止,我遇到了 3 種不同的結構(請參閱下面的 HTML 結構)。 我如何編寫代碼以在不同的結構中進行泛化?
<td valign="bottom">Large accelerated filer</td>
<td valign="bottom"> </td>
<td valign="bottom">☒</td>
<td valign="bottom"> </td>
<td valign="bottom">Accelerated filer</td>
<td valign="bottom"> </td>
<td valign="bottom">☐</td></tr>
<tr style="page-break-inside:avoid ; font-family:Times New Roman; font-size:10pt">
<td valign="bottom"><font style="white-space:nowrap">Non-accelerated filer</font></td>
<td valign="bottom"> </td>
<td valign="bottom">☐ (Do not check if a smaller reporting company)</td>
<td valign="bottom"> </td>
<td valign="bottom">Smaller reporting company</td>
<td valign="bottom"> </td>
<td valign="bottom">☐</td></tr>
<tr style="page-break-inside:avoid ; font-family:Times New Roman; font-size:10pt">
<td valign="bottom">Emerging growth company</td>
<td valign="bottom"> </td>
<td valign="bottom">☐</td>
<td valign="bottom"> </td>
<td valign="bottom"></td>
<td valign="bottom"> </td>
<td valign="bottom"></td></tr>
另一種結構:
filer <font style="FONT-FAMILY:WINGDINGS">x</font> Accelerated filer <font style="FONT-FAMILY:WINGDINGS">¨</font> Non-accelerated filer <font style="FONT-FAMILY:WINGDINGS">¨</font> Smaller reporting company <font style="FONT-FAMILY:WINGDINGS">¨</font> </font>
另一個 :
<tbody><tr>
<td width="63%"></td>
<td valign="bottom" width="2%"></td>
<td width="35%"></td></tr>
<tr>
<td valign="top"> <p style="text-indent:2.00em"><font face="Times New Roman" size="2">Large accelerated filer <font face="WINGDINGS">¨</font></font></p></td>
<td valign="bottom"><font size="1"> </font></td>
<td valign="bottom"><font face="Times New Roman" size="2">Accelerated filer <font face="WINGDINGS">þ</font></font></td></tr>
<tr>
<td valign="top"> <p style="text-indent:2.00em"><font face="Times New Roman" size="2">Non-accelerated filer <font face="WINGDINGS">¨</font> (Do not check if a smaller reporting company)</font></p></td>
<td valign="bottom"><font size="1"> </font></td>
<td valign="bottom"><font face="Times New Roman" size="2">Smaller reporting Company <font face="WINGDINGS">¨</font></font></td></tr>
</tbody>
您可以嘗試使用 3 個 XPath 的這種組合(| 運算符)來獲取您需要的內容(已勾選的項目):
//td[.="☒"]/preceding::td[string-length(.)>1][1]/text()|//font[.="x"]/following::text()[1]|//font[.="þ"]/preceding::text()[1]
您提供的 html 格式不正確。 如果它不起作用,請提供其他東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.