0

谁能给我一段 BeautifulSoup 代码来提取此处找到的表中的一些项目?

这是我的尝试:

from bs4 import BeautifulSoup
from urllib2 import urlopen

url = "http://biology.burke.washington.edu/conus/accounts/../recordview/record.php?ID=1ll&tabs=21100111&frms=1&res=&pglimit=A"

html = urlopen(url).read()
soup = BeautifulSoup(html,"lxml")
tables = soup.findAll("table")

然而,这是失败的——表结果是空的。

抱歉,我是 BeautifulSoup 菜鸟。

谢谢!

4

2 回答 2

1

给定的 url 页面在源中不包含任何表格元素。

表是由javascript生成在 iframe 内。

import urllib
from bs4 import BeautifulSoup

url = 'http://biology.burke.washington.edu/conus/recordview/description.php?ID=1l9l0l421l55llll&tabs=21100111&frms=1&pglimit=A&offset=&res=&srt=&sql2='

html = urllib.urlopen(url).read()
soup = BeautifulSoup(html)
tables = soup.find_all('table')
#print(tables)

硒溶液:

from selenium import webdriver
from bs4 import BeautifulSoup

url = "http://biology.burke.washington.edu/conus/accounts/../recordview/record.php?ID=1ll&tabs=21100111&frms=1&res=&pglimit=A"

driver = webdriver.Firefox()
driver.get(url)
driver.switch_to_frame(driver.find_elements_by_tag_name('iframe')[0])
soup = BeautifulSoup(driver.page_source)
tables = soup.find_all('table')
#print(tables)
driver.quit()
于 2013-07-26T07:44:00.260 回答
1

这是我目前的工作流程:

from bs4 import beautifulsoup
from urllib2 import urlopen
url = "http://somewebpage.com"
html = urlopen(url).read()
soup = BeautifulSoup(html)
tables = soup.find_all('table')
于 2013-11-26T05:46:12.607 回答