twitpy.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:TwitPy 作者: timgrossmann 项目源码 文件源码
def __init__(self, username=None, password=None, nogui=False):
    if nogui:
      self.display = Display(visible=0, size=(800, 600))
      self.display.start()

    chrome_options = Options()
    chrome_options.add_argument('--dns-prefetch-disable')
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--lang=en-US')
    chrome_options.add_experimental_option('prefs', {'intl.accept_languages': 'en-US'})

    # managed_default_content_settings.images = 2: Disable images load, this setting can improve pageload & save bandwidth
    # default_content_setting_values.notifications = 2: Disable notifications
    # credentials_enable_service & password_manager_enabled = false: Ignore save password prompt from chrome
    chrome_prefs = {
      'intl.accept_languages': 'en-US',
      'profile.managed_default_content_settings.images': 2,
      'profile.default_content_setting_values.notifications': 2,
      'credentials_enable_service': False,
      'profile': {
        'password_manager_enabled': False
      }
    }
    chrome_options.add_experimental_option('prefs', chrome_prefs)

    self.browser = webdriver.Chrome('./assets/chromedriver', chrome_options=chrome_options)
    self.browser.implicitly_wait(5)

    self.logFile = open('./logs/logFile.txt', 'a')
    self.logFile.write('Session started - %s\n' \
                       % (datetime.now().strftime('%Y-%m-%d %H:%M:%S')))

    if not username or not password:
      print('Please provide Username and Password')
      return

    self.username = username
    self.password = password
    self.nogui = nogui

    self.followed = 0

    self.ignore_users = []

    self.aborting = False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号