使用beautifulsoup和python抓取iframe

时间:2015-11-28 20:22:11

标签: beautifulsoup

我正试图抓下一页:

https://www.dukascopy.com/swiss/english/marketwatch/sentiment/

更准确地说,是图表中的数字。例如,aud / usd文本旁边的绿色条中的数字为74,19%。我检查了元素,发现这个数字的标签是span。但以下代码不会在图表中返回此数字或任何其他数字:

import requests
from bs4 import BeautifulSoup
r=requests.get('https://www.dukascopy.com/swiss/english/marketwatch/sentiment/')
soup = BeautifulSoup(r.content, "html.parser")
data = soup('span')
print(data)

1 个答案:

答案 0 :(得分:0)

因此,如果你将硒与美丽的汤混合,你将获得硒的所有能力来刮去iframe。

试试这个:

from bs4 import BeautifulSoup
from selenium import webdriver  
from selenium.common.exceptions import NoSuchElementException  
from selenium.webdriver.common.keys import Keys

browser = webdriver.Firefox()
browser.get(bond_iframe)
bond_source = browser.page_source
browser.quit()
soup = BeautifulSoup(bond_source,"html.parser")

for div in soup.findAll('div',attrs={'class':'qs-note-panel'}):
print div

for循环将是您要搜索的div标签