我正在为使用CrawlSpider scrapy的网站编写一个爬虫.
Scrapy提供了一个内置的重复请求过滤器,可根据URL过滤重复的请求.此外,我可以使用CrawlSpider的规则成员过滤请求.
我想要做的是过滤以下请求:
http:://www.abc.com/p/xyz.html?id=1234&refer=5678
Run Code Online (Sandbox Code Playgroud)
如果我已经访问过
http:://www.abc.com/p/xyz.html?id=1234&refer=4567
Run Code Online (Sandbox Code Playgroud)
注意: refer是一个不影响我得到的响应的参数,所以我不在乎该参数的值是否发生变化.
现在,如果我有一个累积所有ID的集合,我可以在我的回调函数parse_item(这是我的回调函数)中忽略它来实现此功能.
但这意味着当我不需要时,我至少仍然会抓住那个页面.
那么我告诉scrapy它不应该基于url发送特定请求的方式是什么?
我正在尝试从我的Rails应用程序发送日历邀请.它似乎在Gmail中正常工作,但在outlook中却没有,它作为附件发送.
我已经尝试过互联网上的所有建议,但是无法让它发挥作用.
class Notifications < ActionMailer::Base
def add_interaction
@i = i
ical = Icalendar::Calendar.new
e = Icalendar::Event.new
e.start = DateTime.now.utc
e.start.icalendar_tzid="UTC" # set timezone as "UTC"
e.end = (DateTime.now + 1.hour).utc
e.end.icalendar_tzid="UTC"
e.organizer @i.interviewer_email
e.created = DateTime.now
e.uid = e.url = "#{HOSTNAME.to_s+'/interaction/'+@i.id.to_s}"
e.summary "#{INTERACTION_TYPE[@i.itype][0]} with #{@i.company}"
e.description <<-EOF
#{INTERACTION_TYPE[@i.itype][0]} with #{@i.company}
Date: #{@i.start_time.strftime('%e %b %Y')}
Time: #{@i.start_time.strftime('%I:%M %p')}
EOF
ical.add_event(e)
ical.custom_property("METHOD", "REQUEST")
email=mail(to: "sample@email.com", subject: "Interview",mime_version: "1.0", content_type:"text/calendar",body:ical.to_ical,content_disposition:"inline; filename=calendar.ics", filename:'calendar.ics')
email.header=email.header.to_s+'Content-Class:urn: content-classes:calendarmessage'
return email
end
end
Run Code Online (Sandbox Code Playgroud)
它被称为
Notifications.add_interaction(Interaction.last).deliver
Run Code Online (Sandbox Code Playgroud)
我也尝试将邮件构造为
email=mail(to: …Run Code Online (Sandbox Code Playgroud) outlook ruby-on-rails actionmailer mime-types ruby-on-rails-4
我需要抓住多家公司的职业网页(经过他们的许可).
决定我使用什么的重要因素
我的疑惑
编辑
使用Watir-webdriver + Nokogiri结束,这样我就可以在存储数据的同时利用活动记录.在提取数据时,Nokogiri比Watir-webdriver快得多.
Scrapy本来会更快,但速度权衡并不像处理scrapy中不同类型网站的复杂性权衡那样重要(例如,我必须通过一些目标网站上的ajax驱动搜索).
希望这有助于某人.
scrapy ×2
actionmailer ×1
mechanize ×1
mime-types ×1
nokogiri ×1
outlook ×1
python ×1
ruby ×1
watir ×1
web-crawler ×1