Python+;Selenium Web抓取动态元素
我正试图从美国证券交易委员会档案网站上提取以下信息 1) 大型加速文件服务器 2) 加速文件管理器 3) 非加速文件管理器 4) 小型报告公司 5) 新兴成长型公司 以下是它在网站上的显示方式:Python+;Selenium Web抓取动态元素,python,selenium,xpath,Python,Selenium,Xpath,我正试图从美国证券交易委员会档案网站上提取以下信息 1) 大型加速文件服务器 2) 加速文件管理器 3) 非加速文件管理器 4) 小型报告公司 5) 新兴成长型公司 以下是它在网站上的显示方式: Large accelerated filer ☒ Accelerated filer ☐ Non-accelerated filer ☐ (Do not check if a smaller reporting company)
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>
文件管理器x加速文件管理器–非加速文件管理器–小型报告公司–
另一个:
<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的组合(|运算符),以获得所需内容(已勾选的项目):
您提供的html格式不正确。如果不起作用,请提供其他内容。我对您的问题进行了一些编辑,如果更改看起来不错,请告诉我,以将其限制在特定问题上,并提供足够详细的信息,以确定适当的答案。避免同时问多个不同的问题。请参阅页面以获得澄清此问题的帮助。谢谢,我使用组合解决了此问题(不完全是您提供的,但稍作调整)
//td[.="☒"]/preceding::td[string-length(.)>1][1]/text()|//font[.="x"]/following::text()[1]|//font[.="þ"]/preceding::text()[1]