我正在努力学习Sinatra。我写了一个脚本来从Craigslist中删除工作列表并将它们列在我的页面上(仅作为练习)。
我终端的输出正是我想要的。但是,在我的页面上,没有任何信息格式正确。我做错了什么?
require 'sinatra'
require 'httparty'
require "nokogiri"
get '/' do
section = params['job']
url = "https://miami.craigslist.org/search/#{section}"
response = HTTParty.get url
html_string = response.body
dom = Nokogiri::HTML(html_string)
links = dom.css("a.hdrlnk")
job_titles = links.map(&:to_str)
job_titles.each_with_index {|job, number| puts "Job #{number}: #{job}"}
end
在我的终端中,我运行文件,这是我的输出:
Job 0: Senior Python Software Developer
Job 1: BILLING/COLLECTIONS/FRONT DESK
Job 2: Front and Back End Web Developer
Job 3: Software Engineer
Job 4: Software Developer
Job 5: In house tech needed for website , networking, drone operation etc
在localhost:4567 /?job = sof,我明白了:
高级Python软件开发人员BILLING / COLLECTIONS / FRONT DESKFront和后端Web开发人员软件工程师软件开发人员需要网站,网络,无人机操作等技术