husc
A simple crawling utility for Ruby.
Description
This project enables site crawling and data extraction with xpath and css selectors. You can also send forms such as text data, files, and checkboxes.
Requirement
Usage
Description of Instance Methods
name | Description |
---|
send | Set the value you want to submit to the form. |
submit | Submit form. |
css | Get node by css selector. |
xpath | Get node by xpath. |
attr | Get node's attribute. |
inner_text | Get node's inner text. |
Simple Example
require 'husc'
url = 'http://www.example.com/'
doc = Husc.new(url)
doc.get('another url')
doc.url
doc.html
doc.tables
Scraping Example
doc.css('div')
doc.css('.main-text')
doc.css('#tadjs')
doc.xpath('//*[@id="top"]/div[1]')
doc.css('div').css('a')[2].attr('href')
doc.css('p').inner_text()
Submitting Form Example
- Specify target node's attribute
- Specify value(int or str) / check(bool) / file_name(str)
- Call submit() with form attribute specified
doc.send(id:'id attribute', value:'value to send')
doc.send(id:'id attribute', value:'value to send')
doc.submit(id:'id attribute')
doc.send(id:'id attribute', file_name:'target file name')
doc.send(id:'id attribute', check:true)
doc.send(id:'id attribute', check:false)
doc.send(id:'id attribute', click:true)
doc.send(id:'id attribute', click:false)
doc.send(name:'name attribute', value:'hello')
doc.send(class:'class attribute', value:100)
Installation
$ gem install husc
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/AjxLab/husc.