Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python+;Selenium Web抓取动态元素_Python_Selenium_Xpath - Fatal编程技术网

Python+;Selenium Web抓取动态元素

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)

我正试图从美国证券交易委员会档案网站上提取以下信息

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&nbsp;accelerated&nbsp;filer</td>
<td valign="bottom">&nbsp;</td>
<td valign="bottom">☒</td>
<td valign="bottom">&nbsp;&nbsp;</td>
<td valign="bottom">Accelerated&nbsp;filer</td>
<td valign="bottom">&nbsp;</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&nbsp;filer</font></td>
<td valign="bottom">&nbsp;</td>
<td valign="bottom">☐&nbsp;&nbsp;(Do not check if a smaller reporting company)</td>
<td valign="bottom">&nbsp;&nbsp;</td>
<td valign="bottom">Smaller&nbsp;reporting&nbsp;company</td>
<td valign="bottom">&nbsp;</td>
<td valign="bottom">☐</td></tr>
<tr style="page-break-inside:avoid ; font-family:Times New Roman; font-size:10pt">
<td valign="bottom">Emerging&nbsp;growth&nbsp;company</td>
<td valign="bottom">&nbsp;</td>
<td valign="bottom">☐</td>
<td valign="bottom">&nbsp;&nbsp;</td>
<td valign="bottom"></td>
<td valign="bottom">&nbsp;</td>
<td valign="bottom"></td></tr>
大型加速文件服务器
☒
加速文件管理器
☐
非加速文件管理器
☐  (不检查是否为较小的报告公司)
小型报告公司
☐
新兴成长型公司
☐
另一个结构:

filer&nbsp;&nbsp;<font style="FONT-FAMILY:WINGDINGS">x</font>&nbsp;&nbsp;&nbsp;&nbsp;Accelerated filer&nbsp;&nbsp;<font style="FONT-FAMILY:WINGDINGS">¨</font>&nbsp;&nbsp;&nbsp;&nbsp;Non-accelerated filer&nbsp;&nbsp;<font style="FONT-FAMILY:WINGDINGS">¨</font>&nbsp;&nbsp;&nbsp;&nbsp;Smaller reporting company&nbsp;&nbsp;<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&nbsp;&nbsp;<font face="WINGDINGS">¨</font></font></p></td>
<td valign="bottom"><font size="1">&nbsp;&nbsp;</font></td>
<td valign="bottom"><font face="Times New Roman" size="2">Accelerated filer&nbsp;&nbsp;<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&nbsp;&nbsp;<font face="WINGDINGS">¨</font>&nbsp;&nbsp; (Do not check if a smaller reporting company)</font></p></td>
<td valign="bottom"><font size="1">&nbsp;&nbsp;</font></td>
<td valign="bottom"><font face="Times New Roman" size="2">Smaller reporting Company&nbsp;&nbsp;<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]