本文整理汇总了Python中selenium.webdriver.Firefox.find_element_by_class_name方法的典型用法代码示例。如果您正苦于以下问题:Python Firefox.find_element_by_class_name方法的具体用法?Python Firefox.find_element_by_class_name怎么用?Python Firefox.find_element_by_class_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.Firefox
的用法示例。
在下文中一共展示了Firefox.find_element_by_class_name方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WebDriver
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import find_element_by_class_name [as 别名]
class WebDriver(object):
def __init__(self, name):
self.webdriver = Firefox()
self.name = name
def get_village(self, name):
village = Village.objects.get(name=name)
return village
def enter_site(self, url):
self.webdriver.get(url)
return self.webdriver.current_url
def get_total_stores(self):
result = self.webdriver.find_element_by_class_name('total')
return result.text
def move_down_page(self):
total_pages = self.get_total_stores()
total = int(total_pages)
for i in xrange(total):
self.webdriver.find_element_by_class_name('maisConteudo').click()
def create_stores(self):
village = self.get_village(self.name)
stores = self.webdriver.find_element_by_class_name('col2-1')
StoresTxt.objects.create(village=village, content=stores)
def run(self):
if self.name:
village = self.get_village(self.name)
self.enter_site(village.url)
self.move_down_page()
self.create_stores()
def tearDown(self):
self.webdriver.quit()
示例2: open_browser
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import find_element_by_class_name [as 别名]
def open_browser(self):
# Open Firefox to charter using Selenium
browser = Firefox()
browser.get('https://www.charter.com/browse/content/new-channel-lineup')
# Click the "choose state" menu using Selenium
wait = WebDriverWait('browser', 20)
button = browser.find_element_by_css_selector('.drop-down-current')
button.click()
# # Identify all states in the list, read as text using Selenium
list_item = browser.find_element_by_class_name('drop-down-list')
states = list_item.text
# print states
# sel_st = raw_input('Type in 2 letter st abbreviation: ')
def prompt(self)
示例3: WeixinSelenium
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import find_element_by_class_name [as 别名]
class WeixinSelenium(Base):
def __init__(self):
self.start_page = START_PAGE
self.end_page = END_PAGE
self.weixin_url = REFER_FIRST
self.driver = Firefox()
self.client = MongoClient(HOST, PORT)
self.collection = self.client[DB][COLLECTION]
self.all_uids = self.uids
def open_weixin_browser(self, word):
try:
self.driver.get(self.weixin_url)
self.driver.set_page_load_timeout(3)
self.driver.find_element_by_id('upquery').send_keys(word)
self.driver.find_element_by_class_name('swz').click()
self.driver.implicitly_wait(3)
urls_uids = self.extract_urls_uids(word=word)
Article(urls_uids=urls_uids, word=word).extract()
except Exception as e:
storage_word.append([word, 0])
self.logger.info('Open weixin error: type <{}>, mag <{}>'.format(e.__class__, e))
self.close_browser()
return True
return False
def get_total_pages_to_word(self):
pages = []
page_id_css = 'pagebar_container'
try:
e = self.driver.find_element_by_id(page_id_css)
for _p in e.text.split():
_p = _p.strip()
if not _p.isdigit():
return pages[-1]
else:
pages.append(int(_p))
return 1
except (NoSuchElementException, NoSuchWindowException, TypeError, IndexError):
pass
def get_query_words(self):
query_words = []
for docs in self.collection.find({}, {'rel': 1, 'conp': 1}).sort([('_id', 1)]):
w = docs['conp']
if w not in query_words:
query_words.append(w)
for item in docs['rel']:
if item not in query_words:
query_words.append(item)
self.client.close()
return query_words
@property
def uids(self):
return {docs['uid'] for docs in in_collection.find({}, {'uid': 1}) if 'uid' in docs}
def extract_urls_uids(self, word):
urls_uids = []
timestamp = [_t.get_attribute('t') for _t in self.driver.find_elements_by_css_selector('div.s-p')]
urls_tits = [(t.get_attribute('href'), self.trim(t.text))
for t in self.driver.find_elements_by_css_selector('h4 a')]
if len(urls_tits) != len(timestamp):
return urls_uids
for index, url_tit in enumerate(urls_tits):
try:
uid = self.md5(timestamp[index] + url_tit[1] + word)
if uid not in self.all_uids:
self.all_uids.add(uid)
urls_uids.append({'url': url_tit[0], 'uid': uid})
except (TypeError, IndexError):
pass
return urls_uids
@staticmethod
def query_index(words, cut_word):
try:
index = words.index(cut_word)
return index
except ValueError:
pass
return 0
@property
def is_forbidden(self):
css_id = 'seccodeForm'
#.........这里部分代码省略.........
示例4: Firefox
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import find_element_by_class_name [as 别名]
from selenium.webdriver import Firefox
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from pygeocoder import Geocoder
import pygmaps
from bs4 import BeautifulSoup
browser = Firefox()
browser.get('https://www.charter.com/browse/content/new-channel-lineup')
wait = WebDriverWait('browser', 20)
button = browser.find_element_by_css_selector('.drop-down-current')
button.click()
list_item = browser.find_element_by_class_name('drop-down-list')
# states = list_item.text
# print states
while True:
st_prompt = raw_input("Enter 2 letter state abbreviation: ")
find_st = browser.find_element_by_link_text(st_prompt.upper())
sel_st = find_st.text + ', USA'
print sel_st
find_st.click() # click to sel state
sleep(1)
try:
list_region = WebDriverWait(browser, 02).until(EC.visibility_of((By.ID, "select-region")))
# list_region = browser.find_element_by_xpath('//*[@id="select-region"]/div[2]') # find Choose Region button
list_region.click()
示例5: TestMaxlifeFeature
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import find_element_by_class_name [as 别名]
class TestMaxlifeFeature(object):
"""
Checks if the maxlife feature is working
"""
def setup_class(self):
"""
Setup: Open a mozilla browser, login
"""
self.browser = Firefox()
self.browser.get('http://localhost:5000/')
token = self.browser.find_element_by_name("token")
password = "foo"
# login
token.send_keys(password)
token.send_keys(Keys.ENTER)
time.sleep(.1)
try:
self.browser.find_element_by_xpath("//input[@value='Logout']")
except NoSuchElementException:
raise ValueError("Can't login!!! Create a user 'foo' with the permissions"
"'read' and 'write' in your PERMISSIONS in the config")
def teardown_class(self):
"""
Tear down: Close the browser
"""
self.browser.quit()
def test_unit_input_exists(self):
unit_input = self.browser.find_element_by_name("maxlife-unit")
assert unit_input is not None
value_input = self.browser.find_element_by_name("maxlife-value")
assert value_input is not None
def fill_form(self):
paste_input = self.browser.find_element_by_id("formupload")
paste_input.send_keys("This is test")
filename_input = self.browser.find_element_by_id("filename")
filename_input.send_keys("test.txt")
contenttype_input = self.browser.find_element_by_id("contenttype")
contenttype_input.send_keys("text/plain")
contenttype_input.send_keys(Keys.ENTER)
def delete_current_file(self):
self.browser.find_element_by_id("del-btn").click()
time.sleep(.2)
self.browser.find_element_by_class_name("btn-primary").click()
def test_paste_keep_forever(self):
self.browser.find_element_by_xpath("//select[@name='maxlife-unit']/option[@value='forever']").click()
value_input = self.browser.find_element_by_name("maxlife-value")
value_input.clear()
value_input.send_keys(1)
self.fill_form()
assert "max life" not in self.browser.find_element_by_tag_name("body").text.lower()
self.delete_current_file()
def test_paste_keep_minutes(self):
self.browser.find_element_by_xpath("//select[@name='maxlife-unit']/option[@value='minutes']").click()
value_input = self.browser.find_element_by_name("maxlife-value")
value_input.clear()
value_input.send_keys(1)
self.fill_form()
assert "max time" in self.browser.find_element_by_tag_name("body").text.lower()
self.delete_current_file()
@pytest.mark.slow
def test_file_gets_deleted(self):
self.browser.find_element_by_xpath("//select[@name='maxlife-unit']/option[@value='minutes']").click()
value_input = self.browser.find_element_by_name("maxlife-value")
value_input.clear()
value_input.send_keys(1)
self.fill_form()
time.sleep(61)
self.browser.find_element_by_id("inline-btn").click()
assert "not found" in self.browser.find_element_by_tag_name("body").text.lower()
示例6: RedFin
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import find_element_by_class_name [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