37,736
社区成员
发帖
与我相关
我的任务
分享
from time import sleep
from geocoder_helpers import normalized
import os
import urllib2
from bs4 import BeautifulSoup
import json
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
url = 'https://www.forrent.com/apartment-community-profile/1012635'
driver = webdriver.Firefox(executable_path='/home/yliu/repos/funnel_objects/listing_sites/geckodriver')
try:
driver.set_page_load_timeout(20)
driver.get(url)
#WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "contactHeading")))
WebDriverWait(driver, 40)
html = driver.page_source
content = BeautifulSoup(html,"lxml")
driver.quit()
return content
except TimeoutException:
print('time out from contact')
return None
<iframe id="jerichotabiframe_0" class="jerichotab" name="jerichotabiframe_0" src="/portal/a/index/welcome" frameborder="0" scrolling="yes" style="width: 1123px; height: 579px; border: 0px;"></iframe>
使用这句跳转driver.switch_to_frame('jerichotabiframe_0')
有时候跳转不过去的话可以先跳回默认:driver.switch_to.default_content()
或者根据页面源码进行跳转