GithubHelp home page GithubHelp logo

tannermares / stack_overflow_scraper Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 32 KB

Simple Sinatra App that uses Mechanize to scrape ruby questions from the tagged page

License: MIT License

Ruby 66.01% HTML 33.99%

stack_overflow_scraper's Introduction

stack_overflow_scraper

Simple Sinatra App that uses Mechanize to scrape ruby questions from the tagged page

stack_overflow_scraper's People

Contributors

tannermares avatar dependabot[bot] avatar

Watchers

James Cloos avatar  avatar

stack_overflow_scraper's Issues

Challenge: Replace Similar Variables with a Hash

Challenge

In order to simplify your application code, and remove redundant view logic, replace your two questions variables with a hash that contains multiple keys. The hash keys should be identical to the section headings in your view.

Once your data is moved into a hash, you'll need to modify your view code to iterate over each of the key value pairs in the hash.

Current app.rb code

require 'rubygems'
require 'sinatra'
require 'mechanize'

get '/' do
    agent = Mechanize.new
    agent.get('http://stackoverflow.com/questions/tagged/ruby')
    @rubyQuestions = agent.page.search('.question-hyperlink')
    agent.get('http://stackoverflow.com/questions/tagged/git')
    @gitQuestions = agent.page.search('.question-hyperlink')
    erb :index
end

Current index.erb code

<html>
    <link rel="stylesheet" href="/bootstrap.min.css">
    <body>
        <h3 class="text-center" style="text-decoration:underline">Ruby Questions</h3>
        <ul class="unstyled text-center">
        <% @rubyQuestions.each do |question| %>
            <li><a href="http://stackoverflow.com<%= question.attributes['href'] %>" ><%= question.text %></a></li>
        <% end %>
        </ul>
        <hr>
        <h3 class="text-center" style="text-decoration:underline">Git Questions</h3>
        <ul class="unstyled text-center">
        <% @gitQuestions.each do |question| %>
            <li><a href="http://stackoverflow.com<%= question.attributes['href'] %>" ><%= question.text %></a></li>
        <% end %>
        </ul>
    </body>
</html>

Tip: In the commit that resolves this issue, you can add the text "Fixes #1", where 1 is the issue number. That will automatically mark this issue as complete when you push the commit to github. Visit this page for more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.