在python中使用beauthulsoup和selenium爬行iframe

2024-05-14 04:13:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我会抓取有iframe的网站。在

http://dart.fss.or.kr/dsaf001/main.do?rcpNo=20150515001896。它在chrome浏览器上有两个选项。(“查看页面源”和“视图框架源代码”都可以。)

但是使用beautifulsoup、urllib2或selenium访问url时,只得到了没有iframe的页面源代码

我如何访问可以在chrome上看到的iframe源代码?在

下面的代码用于访问该网站的页面源代码。在

from selenium import webdriver
import urllib2
from bs4 import BeautifulSoup

url = "http://dart.fss.or.kr/dsaf001/main.do?rcpNo=20150515001896"
f = urllib2.urlopen(url)

#or

browser = webdriver.Chrome()
browser.get(url)
html_source = browser.page_source

#show only the page sources

Tags: orimportbrowserhttpurl源代码网站main