【发布时间】:2012-03-23 13:10:09
【问题描述】:
我正在尝试从该网站访问不同鱼类家族的 URL:http://www.fishbase.org/ComNames/CommonNameSearchList.php?CommonName=Salmon
我希望能够运行一个脚本来打开给定网站的链接,然后能够解析页面中存储的信息。我对网络抓取相当陌生,因此将不胜感激。提前致谢!
这是我目前所拥有的:
import urllib2
import re
from bs4 import BeautifulSoup
import time
fish_url = 'http://www.fishbase.org/ComNames/CommonNameSearchList.php?CommonName=Salmon'
page = urllib2.urlopen(fish_url)
html_doc = page.read()
soup = BeautifulSoup(html_doc)
page = urllib2.urlopen('http://www.fishbase.org/ComNames/CommonNameSearchList.php?CommonName=Salmon').read()
soup = BeautifulSoup(page)
soup.prettify()
for fish in soup.findAll('a', href=True):
print fish['href']
【问题讨论】:
标签: python html web-scraping beautifulsoup