我想了解关于网页抓取和python(以及编程方面的问题),并找到了BeautifulSoup库,它似乎提供了很多可能性。用BeautifulSoup刮掉一系列表格
我试图找出如何最好从这个页面拉动相关信息:
http://www.aidn.org.au/Industry-ViewCompany.asp?CID=3113
我可以进入更详细的关于这一点,但基本上是公司名称,关于它的描述,联系方式,各种公司详细信息/统计数据等
在这个阶段,看看如何彻底隔离这些数据并进行刮擦,以便将所有数据全部放入CSV或其他内容。
我很困惑如何使用BS来获取不同的表格数据。有很多tr和td标签,不知道如何锚定到任何独特的东西。
我想出了如下的代码作为开始的最好:
from bs4 import BeautifulSoup
import urllib2
html = urllib2.urlopen("http://www.aidn.org.au/Industry-ViewCompany.asp?CID=3113")
soup = BeautifulSoup(html)
soupie = soup.prettify()
print soupie
,然后从那里使用正则表达式e.t.c.从清理的文本中提取数据。
但是,必须有更好的方法来使用BS树来做到这一点?或者这个网站的格式不符合BS提供更多帮助?
没有寻找一个完整的解决方案,因为这是一个很大的问题,我想学习,但任何代码片段让我在我的方式将非常感激。
更新
感谢@ZeroPiraeus下面我开始了解如何通过表解析。下面是从他的代码输出:
=== Personnel ===
bodytext Ms Gail Morgan CEO
bodytext Phone: +61.3. 9464 4455 Fax: +61.3. 9464 4422
bodytext Lisa Mayoh Sales Manager
bodytext Phone: +61.3. 9464 4455 Fax: +61.3. 9464 4422 Email: [email protected]
=== Company Details ===
bodytext ACN: 007 350 807 ABN: 71 007 350 807 Australian Owned Annual Turnover: $5M - $10M Number of Employees: 6-10 QA: ISO9001-2008, AS9120B, Export Percentage: 5 % Industry Categories: AerospaceLand (Vehicles, etc)LogisticsMarineProcurement Company Email: [email protected] Company Website: http://www.aerospacematerials.com.au Office: 2/6 Ovata Drive Tullamarine VIC 3043 Post: PO Box 188 TullamarineVIC 3043 Phone: +61.3. 9464 4455 Fax: +61.3. 9464 4422
paraheading ACN:
bodytext 007 350 807
paraheading ABN:
bodytext 71 007 350 807
paraheading
bodytext Australian Owned
paraheading Annual Turnover:
bodytext $5M - $10M
paraheading Number of Employees:
bodytext 6-10
paraheading QA:
bodytext ISO9001-2008, AS9120B,
paraheading Export Percentage:
bodytext 5 %
paraheading Industry Categories:
bodytext AerospaceLand (Vehicles, etc)LogisticsMarineProcurement
paraheading Company Email:
bodytext [email protected]aerospacematerials.com.au
paraheading Company Website:
bodytext http://www.aerospacematerials.com.au
paraheading Office:
bodytext 2/6 Ovata Drive Tullamarine VIC 3043
paraheading Post:
bodytext PO Box 188 TullamarineVIC 3043
paraheading Phone:
bodytext +61.3. 9464 4455
paraheading Fax:
bodytext +61.3. 9464 4422
我的下一个问题是,什么是把这个数据到CSV这将是适用于导入到电子表格的最佳方式?例如,拥有诸如“ABN”“ACN”“公司网站”e.t.c之类的内容。作为列标题,然后将相应的数据作为行信息。
感谢您的任何帮助。
想必你有一个排的每一页刮,然后呢? –
这将是主意,是的。 –