【发布时间】:2013-07-15 20:28:56
【问题描述】:
我正在使用 Python 2.7、mechanize 和 beautifulsoup,如果有帮助,我可以使用 urllib
好的,我正在尝试下载不同 html 表中的几个不同的 zip 文件。我知道特定文件在哪些表中(我知道它们是否在第一个、第二个、第三个......表中)
这是网页中 html 格式的第二个表格:
<table class="fe-form" cellpadding="0" cellspacing="0" border="0" width="50%">
<tr>
<td colspan="2"><h2>Eligibility List</h2></td>
</tr>
<tr>
<td><b>Eligibility File for Met-Ed</b> -
<a href="/content/fecorp/supplierservices/eligibility_list.suppliereligibility.html?id=ME&ftype=1&fname=cmb_me_elig_lst_06_2013.zip">cmb_me_elig_lst_06_2013.zip</td>
</tr>
<tr>
<td><b>Eligibility File for Penelec</b> -
<a href="/content/fecorp/supplierservices/eligibility_list.suppliereligibility.html?id=PN&ftype=1&fname=cmb_pn_elig_lst_06_2013.zip">cmb_pn_elig_lst_06_2013.zip</td>
</tr>
<tr>
<td><b>Eligibility File for Penn Power</b> -
<a href="/content/fecorp/supplierservices/eligibility_list.suppliereligibility.html?id=PP&ftype=1&fname=cmb_pennelig_06_2013.zip">cmb_pennelig_06_2013.zip</td>
</tr>
<tr>
<td><b>Eligibility File for West Penn Power</b> -
<a href="/content/fecorp/supplierservices/eligibility_list.suppliereligibility.html?id=WP&ftype=1&fname=cmb_wp_elig_lst_06_2013.zip">cmb_wp_elig_lst_06_2013.zip</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
我打算使用以下代码进入第二张桌子:
from bs4 import BeautifulSoup
html= br.response().read()
soup = BeautifulSoup(html)
table = soup.find("table", class=fe-form)
我猜 class="fe-form" 是错误的,因为它不起作用,但是该表没有其他属性可以将其与其他表区分开来。所有表格都有 cellpadding="0" cellspacing="0" border="0" width="50%"。我想我不能使用 find() 函数。
所以我试图进入第二张桌子,然后下载此页面上的文件。有人可以给我一些信息来推动我朝着正确的方向前进。我以前使用过表格,但没有使用过表格。我希望有某种方法可以找到我正在寻找的 zip 文件的特定标题,然后下载它们,因为我将永远知道它们的名称
感谢您的帮助, 汤姆
【问题讨论】:
-
这个问题怎么样。我正在尝试使用 python mechanize 下载一个 zip 文件。 zip 文件不是表格形式。谁能给我的提示来学习如何做到这一点?我一直在谷歌中寻找有关使用 python mechanize 浏览表格的信息,但找不到任何东西。我在正确的轨道上吗?
标签: python file download zip mechanize