小编mer*_*980的帖子

beautifulSoup html csv

晚上好,我使用BeautifulSoup从网站中提取一些数据如下:

from BeautifulSoup import BeautifulSoup
from urllib2 import urlopen

soup = BeautifulSoup(urlopen('http://www.fsa.gov.uk/about/media/facts/fines/2002'))

table = soup.findAll('table', attrs={ "class" : "table-horizontal-line"})

print table
Run Code Online (Sandbox Code Playgroud)

这给出了以下输出:

[<table width="70%" class="table-horizontal-line">
<tr>
<th>Amount</th>
<th>Company or person fined</th>
<th>Date</th>
<th>What was the fine for?</th>
<th>Compensation</th>
</tr>
<tr>
<td><a name="_Hlk74714257" id="_Hlk74714257">&#160;</a>£4,000,000</td>
<td><a href="/pages/library/communication/pr/2002/124.shtml">Credit Suisse First Boston International </a></td>
<td>19/12/02</td>
<td>Attempting to mislead the Japanese regulatory and tax authorities</td>
<td>&#160;</td>
</tr>
<tr>
<td>£750,000</td>
<td><a href="/pages/library/communication/pr/2002/123.shtml">Royal Bank of Scotland plc</a></td>
<td>17/12/02</td>
<td>Breaches of money laundering rules</td>
<td>&#160;</td>
</tr>
<tr>
<td>£1,000,000</td> …
Run Code Online (Sandbox Code Playgroud)

python csv beautifulsoup python-2.7

13
推荐指数
1
解决办法
2万
查看次数

使用 Python 从 CSV 中删除不需要的逗号

我需要一些帮助,我有一个包含地址字段的 CSV 文件,无论谁将数据输入到原始数据库中,都使用逗号来分隔地址的不同部分 - 例如:

公园街 5 室

当我尝试使用 CSV 文件时,它会将这个条目视为两个单独的字段,而实际上它是一个字段。我已经使用 Python 去除了逗号之间的逗号,因为很容易将它们与实际应该在那里的逗号区分开来,但是这个问题让我很难过。

任何帮助将不胜感激。

谢谢。

python csv

5
推荐指数
1
解决办法
9864
查看次数

标签 统计

csv ×2

python ×2

beautifulsoup ×1

python-2.7 ×1