Tag: web

在’escape’中:未定义的方法`gsub’用于#(NoMethodError)

嗨,我想废弃一个网页“拿链接”转到那个链接和“废弃它”。 require ‘rubygems’ require ‘scrapi’ require ‘uri’ Scraper::Base.parser :html_parser web = “http://……” def sub_web(linksubweb) uri = URI.parse(URI.encode(linksubweb)) end scraper = Scraper.define do array :items process “div.mozaique>div”, :items => Scraper.define { process “p>a”, :title => :text process “div.thumb>a”, :link => “@href” result :title, :link, } result :items end uri = URI.parse(URI.encode(web)) scraper.scrape(uri).each do |pag| link_full = […]

将字段名称作为参数传递给自定义validation方法Rails 4

我有一个自定义validation方法: def my_custom_validation errors.add(specific_field, “error message”) if specific_field.delete_if { |i| i.blank? }.blank? end 目标是禁止包含[“”]参数通过validation,但我需要调用此方法,如: validate :my_custom_validation #and somehow pass here my field names 例如: validate :my_custom_validation(:industry)

窗口大小改变时调整标题大小

我目前正在一个网站上工作,我需要放一些图像,一些标题和描述将随之而来。 如果浏览器是全屏,则标题显示在一行上; 但是,如果浏览器宽度减小,标题将自动显示在两行上。 以下是浏览器全屏时的外观: 以下是浏览器宽度减小时的外观: 我想这样做,以便当浏览器宽度减小时标题的大小减少,并想知道我该怎么做。 我无法在Google上找到任何好的资源,或者我可能只是没有使用正确的关键字进行搜索。 我正在使用Ruby on Rails和Bootstrap(2.3.2)开发网站。 我也在使用SASS和jQuery,但我是新手。

在url中#/表示什么?

我正在研究ROR网络应用程序。 我的网页url如下所示 – http://dev.ibiza.jp:3000/facebook/report?advertiser_id=2102#/dashboard 在这里我理解advertiser_id是2102,但我无法理解#/ dashboard指向的是什么?

错误:表“用户”上的更新或删除违反表“评论”上的外键约束“fk_rails_03de2dc08c”

我坚持这个错误,无法弄清楚什么是错的。 铁轨已中止! ActiveRecord :: InvalidForeignKey:PG :: ForeignKeyViolation:错误:表“user”上的更新或删除违反了表“comments”上的外键约束“fk_rails_03de2dc08c”DETAIL:Key(id)=(11)仍然从表“comments”引用。 :DELETE FROM“users”WHERE“users”。“id”= $ 1#31

如何使用selenium ruby​​点击IE 11上的打开/保存/取消按钮

尝试使用Selenium和Ruby选择和/或按IE 11中的保存按钮 我试过这段代码: “ driver.action..send_keys(“${KEY_ALT}S”).perform ”和“ RAutomation ” 没有成功,虽然我相信其中任何一个都可行。 我确信在使用这些方法之前必须完成这项工作。 作为最后的手段,我将使用Autoit,虽然我宁愿不。 如果有人可以使用“RAutomation”或“driver.action。+一个或多个上述操作+ .perform”给我一个解决方案,那将非常感谢 IE 11下载文件提示

如何使用Nokogiri在两个HTML注释之间抓取HTML?

我有一些HTML页面,其中要提取的内容用下面的HTML注释标记。 ….. some text Some more elements … 我正在使用Nokogiri并尝试在和 comments之间提取HTML。 我想提取这两个HTML注释之间的完整元素: some text Some more elements 我可以使用这个字符回调获得纯文本版本: class TextExtractor < Nokogiri::XML::SAX::Document def initialize @interesting = false @text = "" @html = "" end def comment(string) case string.strip # strip leading and trailing whitespaces when /^begin content/ # match starting comment @interesting = true when /^end […]

使用{:locale => ,:formats => 缺少模板布局/邮件程序,

我正在关注michael harlt rails教程,但是我收到了这个错误 缺少模板布局/邮件使用{:locale => [:en],:formats => [:html],:variants => [],:handlers => [:raw,:erb,:html,:builder,:ruby,:咖啡,:jbuilder]}。 搜索:*“/ home / ubuntu / workspace / app / views” 预览帐户激活时 这是我的user_mailer.rb class UserMailer < ApplicationMailer def account_activation(user) @user = user mail to: user.email, subject: "Account activation" end def password_reset @greeting = "Hi" mail to: "to@example.org" end end 并且错误突出显示的行 mail to: user.email, subject: […]

Ruby on Rails XPath Json刮痧图像

我正试图从网站上抓取图片。 到目前为止,我正在使用Nokogiri和XPath,但收效甚微。 对于HTML有img和src的典型网站,我可以使用: tmp2 = Nokogiri::HTML(open(site_url)) tmp2.xpath(“//img/@src”).each do |src| …do whatever end 但是,像亚马逊和eBay这样的网站只能用javascript触发某些图像。 如果我查看代码,我可以在数组中看到数据。 例如,来自亚马逊(来源: http : //www.amazon.com/Threads-Thought-Womens-Dreams-X-Small/dp/B00T46V758/ref=sr_1_5? s=apparel&ie=UTF8&qid=1433555447&sr= 1-5 ) : P.when(‘jQuery’, ‘cf’).execute(function($, cf){ P.load.js(‘http://z-ecx.images-amazon.com/images/G/01/browser-scripts/imageBlock-udp-airy/imageBlock-udp-airy-4060168860._V1_.js’); }); P.when(‘A’, ‘jQuery’, ‘ImageBlockATF’, ‘cf’).register(‘ImageBlockBTF’, function(A, $, imageBlockATF, cf){ var data = {“indexToColor”:[],”burjImageBlock”:0,”isSwatchHoverConsistent”:1,”heroFocalPoint”:null,”visualDimensions”:[“color_name”],”productGroupID”:”apparel_display_on_website”,”newVideoMissing”:0,”useIV”:0,”useClickZoom”:null,”useChildVideos”:0,”numColors”:7,”logMetrics”:0,”defaultColor”:”initial”,”airyConfig”:{“enableContinuousPlay”:null,”installFlashButtonText”:”Install Flash Player”,”contentTitle”:null,”autoplayCutOffTimeSeconds”:null,”ageGate”:{“monthNames”:[“January”,”February”,”March”,”April”,”May”,”June”,”July”,”August”,”September”,”October”,”November”,”December”],”deniedPrompt”:”We’re sorry. You are not old enough to watch this video.”,”submitText”:”Submit”,”prompt”:”This video is not intended […]

DRY使用nokogiri搜索网站的每个页面

我想搜索网站的每个页面。 我的想法是找到保留在域内的页面上的所有链接,访问它们并重复。 我必须采取措施,不再重复努力。 所以它很容易开始: page = ‘http://example.com’ nf = Nokogiri::HTML(open(page)) links = nf.xpath ‘//a’ #find all links on current page main_links = links.map{|l| l[‘href’] if l[‘href’] =~ /^\//}.compact.uniq “main_links”现在是活动页面中以“/”开头的链接数组(仅应为当前域上的链接)。 从这里我可以将这些链接提供给上面类似的代码,但我不知道确保我不重复自己的最佳方法。 我想我在访问时会开始收集所有访问过的链接: main_links.each do |ml| visited_links = [] #new array of what is visted np = Nokogiri::HTML(open(page + ml)) #load the first main_link visted_links.push(ml) #push the […]