I\'ve been trying to retrieve stock price from Yahoo! Finance, like for Apple Inc.. My code is like this:(using Python 2)
import requests
from bs4 import Bea
Not sure what you mean by 'dynamic' in this case, but have you considered using CSS selectors?
With Beautifulsoup you could get it e.g like this:
soup.select('div#quote-header-info section span')[0]
And there are some variations you could use on the pattern, such as using the '>' filter.
You could get the same with just lxml
, no need for BeautifulSoup:
import lxml.html as html
page = html.parse(url).getroot()
content = page.cssselect('div#quote-header-info section > span:first-child')[0].text
Which immediately illustrates a more specific selector.
If you're interested in more efficient DOM-traversal, research xpaths.