python类ChromeOptions()的实例源码

anjuke_selenium.py 文件源码 项目:base_function 作者: Rockyzsu 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def anjuke():
    client=pymongo.MongoClient('127.0.0.1',27017)
    db=client['test']
    collection=db['anjuke_selenium']
    options = webdriver.ChromeOptions()
    options.add_argument(
        '--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36')
    options.add_argument('--headless')
    options.add_argument('--disable-gpu')
    browser = webdriver.Chrome(executable_path=r'C:\software\chrome\chromedriver.exe',
                               chrome_options=options)
    browser.implicitly_wait(30)
    for i in range(1,101):
        browser = webdriver.Chrome(executable_path=r'C:\software\chrome\chromedriver.exe',
                                   chrome_options=options)
        browser.get('https://shenzhen.anjuke.com/community/p%d/' %i)
        l = browser.find_elements_by_xpath('//div[@_soj="xqlb"]')
        print len(l)
        for i in l:
            item = dict()
            item['name']=i.find_element_by_xpath('.//div[@class="li-info"]/h3/a').text
            item['url']=i.find_element_by_xpath('.//div[@class="li-info"]/h3/a').get_attribute('href')
            item['location']=i.find_element_by_xpath('.//div[@class="li-info"]/address').text
            item['building_date']=i.find_element_by_xpath('.//div[@class="li-info"]/p').text
            item['price']= i.find_element_by_xpath('.//div[@class="li-side"]/p/strong').text
            #print item
            collection.insert(item)
        browser.close()
selenium_usage.py 文件源码 项目:base_function 作者: Rockyzsu 项目源码 文件源码 阅读 47 收藏 0 点赞 0 评论 0
def template():
    options = webdriver.ChromeOptions()
    options.add_argument(
        '--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36')
    driver = webdriver.Chrome(executable_path=r'C:\software\chrome\chromedriver.exe',
                              chrome_options=options)
    driver.implicitly_wait(40)
conftest.py 文件源码 项目:bowtie 作者: jwkvam 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def chrome_driver():
    """Set up chrome driver."""
    options = webdriver.ChromeOptions()
    if platform == 'darwin':
        options.binary_location = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
    else:
        options.binary_location = '/usr/bin/google-chrome-stable'
    options.add_argument('headless')
    options.add_argument('window-size=1200x800')
    driver = webdriver.Chrome(chrome_options=options)
    yield driver
    driver.quit()
base.py 文件源码 项目:wagtail-startproject 作者: leukeleu 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_driver(cls):
        """Setup a Chrome webdriver"""

        options = webdriver.ChromeOptions()
        options.add_argument('headless')
        cls.set_driver_options(options)
        try:
            driver = webdriver.Chrome('./node_modules/.bin/chromedriver', chrome_options=options)
        except WebDriverException:
            raise unittest.SkipTest('Not able to start Chrome driver.')
        return driver
runner.py 文件源码 项目:dispatch-console-tests 作者: jdanekrh 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def initialize_local_chrome():
    options = webdriver.ChromeOptions()
    options.binary_location = '/home/jdanek/.nix-profile/bin/google-chrome-stable'
    driver = webdriver.Chrome(chrome_options=options)
    return driver
crawlLagou.py 文件源码 项目:Kad 作者: liuzhuocpp 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def getChromeBrowser():
    myProxy= 'proxy.abuyun.com:9020'
    option = webdriver.ChromeOptions()
    option.add_argument('--user-data-dir=C:\Users\LZ\AppData\Local\Google\Chrome\User Data\Default') #????????????
    option.add_argument('--proxy-server=%s' % myProxy)
    browser = webdriver.Chrome(executable_path="chromedriver", chrome_options=option)
    return browser
lootan.py 文件源码 项目:pythoner 作者: jsRuner 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def openBrower():
    print("?????...")

    # driver = webdriver.Firefox()
    # driver = webdriver.Ie()
    options = webdriver.ChromeOptions()
    options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"])
    driver = webdriver.Chrome(chrome_options=options)

    # driver = webdriver.Chrome()
    return driver
hunter.py 文件源码 项目:selenium-toy 作者: blackmatrix7 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self):
        # ??????
        options = webdriver.ChromeOptions()
        prefs = {"profile.managed_default_content_settings.images": 2}
        options.add_experimental_option("prefs", prefs)
        if platform.system() == 'Darwin':
            executable_path = '{0}/{1}'.format(current_config.PROJ_PATH, 'chromedriver')
        else:
            executable_path = 'chromedriver.exe'
        self.driver = webdriver.Chrome(executable_path=executable_path, chrome_options=options)
        self.driver.implicitly_wait(current_config['TIME_OUT'])
        self.driver.set_window_size(1440, 900)
tests.py 文件源码 项目:python-web-pdb 作者: romanvm 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def setUpClass(cls):
        if sys.platform == 'win32':
            cls.browser = webdriver.Firefox()
        else:
            options = webdriver.ChromeOptions()
            options.add_argument('headless')
            options.add_argument('disable-gpu')
            cls.browser = webdriver.Chrome(chrome_options=options)
        cls.browser.get('http://127.0.0.1:5555')
        cls.stdin = cls.browser.find_element_by_id('stdin')
        cls.send_btn = cls.browser.find_element_by_id('send_btn')
LoginController.py 文件源码 项目:weiboCrawler 作者: hjydzh 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_chrome():
    profile_dir=r"C:\Users\junyu\AppData\Local\Google\Chrome\User Data"
    options = webdriver.ChromeOptions()
    #options.add_argument("user-data-dir="+os.path.abspath(profile_dir))
    options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"])
    return webdriver.Chrome('G:/lessUsedTools/browser/chrome/chromedriver.exe',chrome_options=options)
html_downloader.py 文件源码 项目:wechat_spider 作者: CoolWell 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def download_articles_chrome(self, url):
        # service_args = ['--load-images=no', ]
        profile_dir = r"D:\MyChrome\Default"
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument("--user-data-dir=" + os.path.abspath(profile_dir))
        # PROXY = "123.56.238.200:8123"
        # # j = random.randint(0, len(proxys)-1)
        # # proxy = proxys[j]
        # chrome_options.add_argument('--proxy-server=%s' % PROXY)
        # chrome_options.add_extension('')??crx??
        # service_args = ['--proxy=localhost:9050', '--proxy-type=socks5', '--load-images=no', ]
        try:
            driver = webdriver.Chrome(r'C:\Python27\chromedriver', chrome_options=chrome_options)
        except Exception as e:
            print(datetime.datetime.now())
            print(url)
            print(e)
        else:

            try:
                driver.set_page_load_timeout(30)
                driver.get(url)
                driver.implicitly_wait(2)
                html = driver.page_source
                return html
            except:
                print(datetime.datetime.now())
                print(url)
                # selenium.common.exceptions.TimeoutException:
                # return self.download_acticles(url)
                return None
            finally:
                driver.quit()
utils.py 文件源码 项目:Needl 作者: eth0izzle 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_browser():
    chromedriver = os.path.join(needl.args.datadir, 'chromedriver')
    if not os.path.exists(chromedriver):
        raise FileNotFoundError("Could not find chromedriver executable at %s. Download it for your platform at https://chromedriver.storage.googleapis.com/index.html?path=2.33/", chromedriver)

    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('headless')
    chrome_options.add_argument('window-size=1024x3000')
    chrome_options.add_argument("user-agent=" + get_line(os.path.join(needl.args.datadir, 'user-agents.txt')))

    return webdriver.Chrome(executable_path=chromedriver, chrome_options=chrome_options)
ItsLearningScraper.py 文件源码 项目:Pirka 作者: Mkohm 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, username: str, password: str):
        """
        This method sets up scraper, and logs in to Its Learning. It enables the other methods to scrap
        content, like calendar feed, exercises and course list.
        :param username: FEIDE-username
        :param password: FEIDE-password
        """

        self.username = username
        self.password = password

        # Initializes the correct version of chromedriver with regards to OS
        driver_directory = os.path.dirname(__file__)
        if platform.system() == "Windows":
            relative_path = "chromedriver.exe"
        else:
            relative_path = "chromedriver"
        absolute_file_path = os.path.join(driver_directory, relative_path)
        chrome_profile = webdriver.ChromeOptions()
        self.driver = webdriver.Chrome(executable_path=absolute_file_path)

        self.driver.get("http://www.ilearn.sexy")  # Shortcut to itslearning

        # logs into Its Learning. After this the "driver" contains the main page in Its Learning
        username_field = self.driver.find_element_by_name("feidename")
        username_field.send_keys(username)
        password_field = self.driver.find_element_by_name("password")
        password_field.send_keys(password)
        password_field.submit()
drivers.py 文件源码 项目:selenium_extensions 作者: pythad 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def chrome_driver(executable_path=None, run_headless=False,
                  load_images=True, use_proxy=None):
    '''Function to initialize ``selenium.webdriver.Chrome`` with extended options

    Args:
        executable_path (str): path to the chromedriver binary. If set to ``None`` selenium will serach for ``chromedriver`` in ``$PATH``.
        run_headless (bool): boolean flag that indicates if chromedriver has to be headless (without GUI).
        load_images (bool): boolean flag that indicates if Chrome has to render images.
        use_proxy (str): use http proxy in <host:port> format.

    Returns:
        selenium.webdriver.Chrome: created driver.

    Note:
        In order to create Chrome driver Selenium requires `Chrome <https://www.google.com/chrome/browser/desktop/index.html>`_ to be installed and `chromedriver <https://sites.google.com/a/chromium.org/chromedriver/>`_ to be downloaded.

    Warning:
        Headless Chrome is shipping in Chrome 59 and in Chrome 60 for Windows. Update your Chrome browser if you want to use ``headless`` option.
    '''
    chrome_options = webdriver.ChromeOptions()
    if run_headless:
        chrome_options.add_argument('headless')
    if not load_images:
        prefs = {'profile.managed_default_content_settings.images': 2}
        chrome_options.add_experimental_option('prefs', prefs)
    if use_proxy:
        chrome_options.add_argument('proxy-server=' + use_proxy)
    if executable_path:
        driver = webdriver.Chrome(chrome_options=chrome_options,
                                  executable_path=executable_path)
    else:
        driver = webdriver.Chrome(chrome_options=chrome_options)
    return driver
middlewares.py 文件源码 项目:Spider 作者: poluo 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self):
        self.cookies = None
        path = "C:\Program Files (x86)\Google\Chrome\chromedriver.exe"
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument("--incognito")
        self.driver = webdriver.Chrome(service_args=['--load-images=no'], executable_path=path,
                                       chrome_options=chrome_options)
        self.action = ActionChains(self.driver)
        self.retry_login()
browser.py 文件源码 项目:insta_browser 作者: aLkRicha 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self, debug=False, chrome=False, cookie_path=None, log_path=None, db_path=None,
                 exclude=None):
        options = webdriver.ChromeOptions()
        options.add_argument('headless')
        options.add_argument('--window-size=900,768')
        self.browser = webdriver.Chrome(chrome_options=options)
        self.browser.implicitly_wait(10)

        self.cookie_path = cookie_path
        self.exclude = exclude or []
        self.chrome = chrome
        self.logger = Logger(log_path, debug)
        self.db = BrowserDB(self.logger, db_path)
test_selenium_astride.py 文件源码 项目:python_selenium_astride 作者: reclamador 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def setUp(self):
        self.app = self.create_app()
        options = webdriver.ChromeOptions()
        options.add_argument('headless')
        options.add_argument('disable-gpu')
        self.browser = webdriver.Chrome(options=options)
        self.browser.implicitly_wait(3)
PostToFacebook.py 文件源码 项目:Taurauto-Sharer 作者: sameerkumar18 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self):
        self.url = 'https://www.facebook.com'
        chrome_options = webdriver.ChromeOptions()
        prefs = {"profile.default_content_setting_values.notifications": 2}
        chrome_options.add_experimental_option("prefs", prefs)
        self.driver = webdriver.Chrome(chrome_options=chrome_options)#,'__path__' maybe required for Windows
        self.driver.get(self.url)
AutoShareFacebook.py 文件源码 项目:Taurauto-Sharer 作者: sameerkumar18 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self):
        self.url = 'https://www.facebook.com'
        chrome_options = webdriver.ChromeOptions()
        prefs = {"profile.default_content_setting_values.notifications": 2}
        chrome_options.add_experimental_option("prefs", prefs)
        self.driver = webdriver.Chrome(chrome_options=chrome_options)#,'__path__' maybe required for Windows
        self.driver.get(self.url)
AutoShareFacebook.py 文件源码 项目:Taurauto-Sharer 作者: sameerkumar18 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self):
        self.url = 'https://www.facebook.com'
        chrome_options = webdriver.ChromeOptions()
        prefs = {"profile.default_content_setting_values.notifications": 2}
        chrome_options.add_experimental_option("prefs", prefs)
        self.driver = webdriver.Chrome(chrome_options=chrome_options)
        self.driver.maximize_window()
        self.driver.get(self.url)


问题


面经


文章

微信
公众号

扫码关注公众号