gpt4 book ai didi

Ruby Mechanize Outlook Web Access

转载 作者:数据小太阳 更新时间:2023-10-29 08:01:31 26 4
gpt4 key购买 nike

我正在尝试使用 ruby​​ mechanize 从我的 outlook web 访问帐户访问特定的电子邮件。

我正在使用以下代码。

    require 'mechanize'    require 'logger'    a = Mechanize.new    a.cookie_jar(HTTP::Cookies.new)    a.log = Logger.new('log1.log')     a.get('htts://webmail.xxxxxxx.org/') do |page|      my_page = page.form_with(:action => '/owa/auth.owa') do |f|        f.username  = "------------"        f.password  = "------------"      end.click_button      #a.cookie_jar.load('cookies.yml')      a.get('https://webmail.xxxxxxx.org/owa/Inbox/?Cmd=contents&Page=1') do |p|          file = File.new("new.xml","w+")          file.puts p.parser.to_xml          file.close      end   end

为什么这段代码不起作用?

最佳答案

这是使用 nokogiri 和 mechanize 到 SSL owa 交换网站的有效 OWA 检索脚本。

它需要安装 ruby​​gems、mechanize (+deps) 和 highline。

    require 'rubygems'    require 'mechanize'    require 'logger'    require 'highline/import'    @url = 'https://email.***.***/Exchange'    @mechanize = Mechanize.new { |a| a.log = Logger.new('./log1.log') }    #In case you dont have trusted certs    @mechanize.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE    @mechanize.user_agent_alias = 'Windows Mozilla'    @mechanize.keep_alive = 'enable'    username = ask("Enter your username: ")    domain = ask("Enter your domain: ")    password = ask("Enter your password: ") {|q| q.echo = "*" }    @mechanize.get(@url) do |page|      form = page.forms[0]      form["username"] = domain + '\\' + username      form["password"] = password      page = form.submit     end    ## Common Mailbox Schemes    @mailbox = "#{username}"    # @mailbox = "#{username}@#{domain}.#{tld}"    # @mailbox = "#{username}@#{domain}"    @inbox = @url + "/#{@mailbox}/Inbox/?Cmd=contents&Page=1&View=Unread%20Messages"    inboxlisting = @mechanize.get(@inbox) do |page|      fragment = Nokogiri::HTML(page.body)      ["//img[@src='/exchweb/img/icon-msg-unread.gif']"].each do |xpathq|        puts "Found #{fragment.xpath(xpathq).count} new emails."      end        ["//img[@src='/exchweb/img/icon-mtgreq.gif']"].each do |xpathq|           puts "Found #{fragment.xpath(xpathq).count} new meeting requests."      end      end

示例脚本输出:

    $ ruby ./owa.rb     Enter your username: john.doe    Enter your domain: mywork    Enter your password: ************    Found 31 new emails.    Found 3 new meeting requests.

关于Ruby Mechanize Outlook Web Access,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8030189/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com