本文整理汇总了Python中selenium.webdriver.Firefox.switch_to_frame方法的典型用法代码示例。如果您正苦于以下问题:Python Firefox.switch_to_frame方法的具体用法?Python Firefox.switch_to_frame怎么用?Python Firefox.switch_to_frame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.Firefox
的用法示例。
在下文中一共展示了Firefox.switch_to_frame方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RedFin
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import switch_to_frame [as 别名]
#.........这里部分代码省略.........
except:
property_data['beds'] = 'N/A';print('beds not found')
try:
property_data['baths'] = self.soup.find('div', attrs={'data-rf-test-id': 'abp-baths'}).find(
'div').get_text()
except:
property_data['baths'] = 'N/A';print('baths not found')
try:
property_data['sqFt'] = self.soup.find('div', attrs={'data-rf-test-id': 'abp-sqFt'}).find('span', attrs={
'class': 'main-font statsValue'}).get_text()
except:
property_data['sqFt'] = 'N/A';print('sqFt not found')
try:
property_data['price_per_sqFt'] = self.soup.find('div', attrs={'data-rf-test-id': 'abp-sqFt'}).find('div',
attrs={
"data-rf-test-id": "abp-priceperft"}).get_text()
except:
property_data['price_per_sqFt'] = 'N/A';print('price_per_sqFt not found')
try:
property_data['year_built'] = self.soup.find('span', attrs={"data-rf-test-id": "abp-yearBuilt"}).find(
'span', attrs={'class': 'value'}).get_text()
except:
property_data['year_built'] = 'N/A';print('year_built not found')
try:
property_data['days_on_redfin'] = self.soup.find('span',
attrs={"data-rf-test-id": "abp-daysOnRedfin"}).find('span',
attrs={
'class': 'value'}).get_text()
except:
property_data['days_on_redfin'] = 'N/A';print('days_on_redfin not found')
try:
property_data['status'] = self.soup.find('span', attrs={"data-rf-test-id": "abp-status"}).find('span',
attrs={
'class': 'value'}).get_text()
except:
property_data['status'] = 'N/A';print('status not found')
property_data['summary'] = self.soup.find('div', attrs={'class': 'remarks'}).get_text()
for row in self.soup.find('div', attrs={'class': 'more-info-div'}).find_all('tr'):
cells = row.find_all('td')
property_data[cells[0].get_text().strip()] = cells[1].get_text().strip()
# use loops to maintain data structure ina dict
property_data['property_details'] = OrderedDict()
for category in self.soup.find('div', attrs={'class': 'amenities-container'}).children:
key = category.contents[0].get_text().strip()
property_data['property_details'][key] = OrderedDict()
for row in category.contents[1].find_all('div', attrs={'class': 'amenity-group'}):
key2 = row.find('h4').get_text()
property_data['property_details'][key][key2] = []
for row2 in row.find_all('li'):
property_data['property_details'][key][key2].append(row2.get_text())
property_data['propert_history'] = []
for row in self.soup.find_all('tr', attrs={'id': reg_property_history_row}):
data_cells = row.find_all('td')
history_data_row = OrderedDict()
history_data_row['date'] = data_cells[0].get_text()
history_data_row['event & source'] = data_cells[1].get_text()
history_data_row['price'] = data_cells[2].get_text()
history_data_row['appreciation'] = data_cells[3].get_text()
property_data['propert_history'].append(history_data_row)
property_data['url'] = 'https://www.redfin.com' + property_url
self.output_data.append(property_data)
return property_data
def use_browser(self):
self.use_selenium = True
firefox_profile = FirefoxProfile()
# might as well turn off images since we don't need them
if self.use_proxies:
# if use proxies is true load firefox with proxies
firefox_profile.set_preference("permissions.default.image", 2)
proxy_host, proxy_port = choice(self.proxies).split(':')
firefox_profile.set_preference("network.proxy.type", 1)
firefox_profile.set_preference("network.proxy.http", proxy_host)
firefox_profile.set_preference("network.proxy.http_port", int(proxy_port))
firefox_profile.set_preference("network.proxy.ssl", proxy_host)
firefox_profile.set_preference("network.proxy.ssl_port", int(proxy_port))
self.driver = Firefox(firefox_profile)
self.driver.implicitly_wait(2)
def get_page_selenium(self, page_url):
self.driver.get(page_url)
self.selenium_bypass_captcha()
return self.driver.page_source
def selenium_bypass_captcha(self):
# basic code for handling captcha
# this requires the user to actually solve the captcha and then continue
try:
self.driver.switch_to_frame(self.driver.find_element_by_xpath('//iframe[@title="recaptcha widget"]'))
self.driver.find_element_by_class_name('recaptcha-checkbox-checkmark').click()
print('solve captcha ( pop up only ) and press enter to continue')
raw_input()
self.driver.switch_to_default_content()
self.driver.find_element_by_id('submit').click()
except Exception as e:
pass
示例2: Firefox
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import switch_to_frame [as 别名]
#!/usr/bin/env python3
#from selenium.webdriver import Firefox
from selenium import webdriver
from selenium.webdriver import Firefox
browser = Firefox()
browser.get('http://www.morningstar.com/stocks/xnas/aapl/quote.html')
iframe = browser.switch_to_frame('mainFrame')
b.switch_to_frame(iframe)
print(b.page_source)