Skip to main content
 首页 » 编程设计

python之Beautiful Soup 并提取数组的字符串部分

2025年05月04日20wuhuacong

考虑这个 URL: http://www.nyse.com/about/listed/chn.html

我正在尝试检索此字符串:'Pacific Ex Japan Funds' 但它不在汤中!?!

fundCode = 'chn' 
url = 'http://www.nyse.com/about/listed/' + fundCode + '.html' 
html = urllib2.urlopen(url) 
soup = BeautifulSoup(html) 

这很奇怪,因为 table 的其他部分都在汤里。

有什么想法吗?

请您参考如下方法:

如果您下载 HTML(没有浏览器)

content = html.read() 

您会看到页面数据是由 JavaScript 函数提供的。

要从此页面提取信息,您需要一个可以处理 JavaScript 的库。

一种方法是使用 Selenium , 另一种方法是使用 PyQt's WebKit .