mechanize

Ruby Mechanize: user agents?

允我心安 提交于 2019-12-02 20:29:26
How many user agents are there in Mechanize? Is there a handy list of all the user agent options anywhere? Adrian Yes. Look at https://github.com/sparklemotion/mechanize/blob/master/lib/mechanize.rb#L115 : AGENT_ALIASES = { 'Windows IE 6' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)', 'Windows IE 7' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)', 'Windows Mozilla' => 'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6', 'Mac Safari' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; de-at)

Python mechanize - two buttons of type 'submit'

女生的网名这么多〃 提交于 2019-12-02 20:19:35
I have a mechanize script written in python that fills out a web form and is supposed to click on the 'create' button. But there's a problem, the form has two buttons. One for 'add attached file' and one for 'create'. Both are of type 'submit', and the attach button is the first one listed. So when I select the forum and do br.submit(), it clicks on the 'attach' button instead of 'create'. Extensive Googling has yielded nothing useful for selecting a specific button in a form. Does anyone know of any methods for skipping over the first 'submit' button and clicking the second? I tried using the

How to test a ruby application which uses mechanize

安稳与你 提交于 2019-12-02 19:13:52
I wrote a small program that uses Mechanize to traverse a site. I want to write tests for it, but don't want it to actually go log onto the site every time I run the tests. I would like to mock the internet, so that when it goes to some site, it simply returns the stored results. Here is a small example, pretend my code's purpose was to pull links off of the google homepage, so I write a test to ensure the first link my code finds has the text "Images". I might write something like this: require 'rubygems' require 'mechanize' require 'test/unit' def my_code_to_find_links google = WWW:

Which is best in Python: urllib2, PycURL or mechanize?

我们两清 提交于 2019-12-02 13:47:54
Ok so I need to download some web pages using Python and did a quick investigation of my options. Included with Python: urllib - seems to me that I should use urllib2 instead. urllib has no cookie support, HTTP/FTP/local files only (no SSL) urllib2 - complete HTTP/FTP client, supports most needed things like cookies, does not support all HTTP verbs (only GET and POST, no TRACE, etc.) Full featured: mechanize - can use/save Firefox/IE cookies, take actions like follow second link, actively maintained (0.2.5 released in March 2011) PycURL - supports everything curl does (FTP, FTPS, HTTP, HTTPS,

Python Mechanize Error +

送分小仙女□ 提交于 2019-12-02 11:42:12
问题 I am new to python (done some java in the past). I recently decided to automate a process that takes me about 20 hours once a year. I need to login to a vendor's website, with a login form they have. That then loads a new form which I can select an order from, and then it loads yet another form I can submit an item number to. This then loads the page with sizes of the item and price per size, I take this information and put it into a spreadsheet. The row has columns based on number of sizes

Passing multiple files to input node with Watir (using Ruby)

和自甴很熟 提交于 2019-12-02 09:28:16
问题 So I have hit a bit of a snag. I am trying to automate a test case where I need to pass multiple files to an input node and I cannot figure out how to do so. I can use either Mechanize or Watir, but have found very little information on a topic that seems relatively major in automation. In the snippets below, I'm using Watir with Ruby. The main issue I'm having is that it seems when multiple files are selected, the input node is no longer visible. The input node does accept multiple files,

Get JavaScript variable using Mechanize

半世苍凉 提交于 2019-12-02 08:43:06
问题 I want to get a JavaScript variable from https://admin.booking.com/hotel/hoteladmin in head > script > var token . I don't know how this variable is set by the browser because when I get this page from Mechanize I get: var token = '' || 'empty-token', Here is the code I use to GET this page: login_url = "https://admin.booking.com/hotel/hoteladmin" agent = Mechanize.new agent.verify_mode= OpenSSL::SSL::VERIFY_NONE page = agent.get(login_url) 回答1: If you want to access this token via JavaScript

Finding next input element using Mechanize?

守給你的承諾、 提交于 2019-12-02 08:22:52
问题 Using Mechanize, is it possible to find a phrase in the HTML of a page, for example, "email", and find the next <input* after that, and fill in that input field, and only that field? 回答1: Mechanize uses Nokogiri internally to handle its DOM parsing, which is the basis of its ability to locate different elements in a page. It's possible to access the parsed DOM, and, through it use Nokogiri to locate elements Mechanize doesn't normally let us find. For instance: require 'mechanize' agent =

Undefined method 'click' for nil:NilClass (Mechanize) [closed]

為{幸葍}努か 提交于 2019-12-02 07:51:13
I am building a script using Mechanize to scrape data from a website. The script is supposed to click on the "Read biography" link and then scrape the biography of the member on the next page. Here is the script in the Rake file: require 'mechanize' require 'date' require 'json' task :testing2 do agent = Mechanize.new page = agent.get("https://www.congress.gov/members") page_links = page.links_with(href: %r{.*/member/\w+}) member_links = page_links[0...2] members = member_links.map do |link| member = link.click name = member.search('title').text.split('|')[0] institution = member.search('td~

Passing multiple files to input node with Watir (using Ruby)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 06:40:58
So I have hit a bit of a snag. I am trying to automate a test case where I need to pass multiple files to an input node and I cannot figure out how to do so. I can use either Mechanize or Watir, but have found very little information on a topic that seems relatively major in automation. In the snippets below, I'm using Watir with Ruby. The main issue I'm having is that it seems when multiple files are selected, the input node is no longer visible. The input node does accept multiple files, and passing in a single path does result in a successful upload, like so. path1 = "/path/to/file.json"