擅长:python、mysql、java
<p>正如我在评论中提到的,这里是使用替代源的新代码。这比我现在想的要容易得多,因为我实际上得到了回报数据。=)</p>
<pre><code>url = ('http://www.marketwatch.com/investing/stock/vdrm')
page = urllib.request.urlopen(url).read()
soup = BeautifulSoup(page, "lxml")
vol = soup.find('span', attrs={'class': 'volume last-value'})
volume = vol.text.strip()
chg = soup.find('span', attrs={'class': 'change percent q'})
change = chg.text.strip()
print ("Vol: {} Change: {}".format(volume, change))
</code></pre>