gpt4 book ai didi

ruby - 如何使用 Mechanize 抓取电子邮件地址而不将 `[email protected]` 作为值

转载 作者:行者123 更新时间:2023-12-04 16:19:26 25 4
gpt4 key购买 nike

在抓取客户电子邮件地址的单个订单(可以在此处找到完整的 HTML 代码:http://pastebin.com/SaLc5jHu)页面(我的 OpenCart 商店的管理部分)时,我得到以下电子邮件地址值:

[email protected]
/* <![CDATA[ */
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
这是代码:
require 'mechanize'

a = Mechanize.new

a.get('http://exampleshop.nl/admin/') do |page|

# Select the login form
login_form = page.forms.first

# Insert the username and password
login_form.username = 'username'
login_form.password = 'password'

# Submit the login information
dashboard_page = a.submit(login_form, login_form.buttons.first)

# Check if the login was successfull
puts check_1 = dashboard_page.title == 'Dashboard' ? "CHECK 1 DASHBOARD SUCCESS" : "CHECK 1 DASHBOARD FAIL"

# Visit the orders index page to scrape some standard information
orders_page = a.click(dashboard_page.link_with(:text => /Bestellingen/))

# pp orders_page # => http://pastebin.com/L3zASer6

# Check if the visit is successful
puts check_2 = orders_page.title == 'Bestellingen' ? "CHECK 2 ORDERS SUCCESS" : "CHECK 2 ORDERS FAIL"

# Search for all #singleOrder table row's and put them in variable all_single_orders
all_single_orders = orders_page.search("#singleOrder")

# Scrape the needed information (the actual save to database is omitted)
all_single_orders.each do |order|
# Set links for each order
order_link = order.at_css("a")['href'] #Assuming first link in row

order_id = order.search("#orderId").text # => 259
order_status = order.search("#orderStatus").text # => Bestelling ontvangen
order_amount = order.search("#orderAmount").text # => € 41,94

# Visit a single order page to fetch more detailed information
single_order_page = orders_page.link_with(:href => order_link).click

# Fetch more information
puts first_name = single_order_page.search(".firstName").text
puts last_name = single_order_page.search(".lastName").text
puts email = single_order_page.search(".email").text # => [email protected] /* <![CDATA[ */...
puts postal_code = single_order_page.search(".postalCode").text
puts address = single_order_page.search(".address").text
puts product_quantity = single_order_page.search(".orderQuantity").text
end
end
有任何想法吗?我正在使用 Ruby 2.0.0 和 Mechanize 2.7.3 并安装了 CloudFlare。
更新
现在工作。要使其正常工作,只需禁用 CloudFlare 的应用程序面板 ( https://www.cloudflare.com/cloudflare-apps ) 内的 ScrapeShield 电子邮件混淆选项。

最佳答案

它无法正常工作,因为一个名为 ScrapeShield 的 CloudFlare 应用程序被激活。

要使其正常工作,只需禁用 ScrapeShield E-mail obfuscation应用程序面板内的选项 ( https://www.cloudflare.com/cloudflare-apps )。

关于ruby - 如何使用 Mechanize 抓取电子邮件地址而不将 `[email protected]` 作为值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20483206/

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