【问题标题】:Scraping external website but returns "You must use a JavaScript capable browser with this site." error抓取外部网站但返回“您必须在该网站上使用支持 JavaScript 的浏览器”。错误
【发布时间】:2015-01-21 15:45:37
【问题描述】:

我在 Ruby on Rails 中使用 rake 任务。我有一个网站,我需要登录才能抓取该网站。我填了表格。

form[:login] = user_name
form[:pw] = password
form.submit

这会返回错误

#<Mechanize::Page
 {url
  #<URI::HTTPS:0x007fa36a0037b8 URL:https://pulse2.com/system/JSAuth/NoScript.html>}
 {meta_refresh}
 {title "You must use a JavaScript capable browser with this site."}
 {iframes}
 {frames}
 {links}
 {forms}>

这很奇怪,因为 a) 我可以为 scraper 开启 JS 功能 b) 这是网站本身的问题吗?

[编辑] 更多信息。当我查看表格时,它看起来像这样。需要注意的一件事是 {action "/system/JSAuth/NoScript.html"}。我相信这就是我无法提交操作的原因。有没有办法解决这个问题??

#<Mechanize::Form
   {name "mainform"}
   {method "POST"}
   {action "/system/JSAuth/NoScript.html"}
   {fields
    [hidden:0x3fc5b7d7d8b0 type: hidden name: referer value: ]
    [hidden:0x3fc5b7d7d75c type: hidden name: VerLoginAttempt value: 1]
    [hidden:0x3fc5b7d7d608 type: hidden name: FormName value: LoginMain]
    [text:0x3fc5b7d7d4b4 type: text name: VerLoginID value: ]
    [field:0x3fc5b7d7d360 type: password name: VerPassword value: ]}
   {radiobuttons}
   {checkboxes
    [checkbox:0x3fc5b7d7d234 type: checkbox name: RCRememberMe value: false]}
   {file_uploads}
   {buttons [submit:0x3fc5b7d7d090 type: submit name:  value: Login]}>

【问题讨论】:

  • 您可能需要修改用户代理才能通过此操作。不知道你会如何在 Rails 中做到这一点
  • 你会将用户代理修改成什么?
  • 嘿,如上所述,我将用户代理更改为 firefox。但我仍然收到相同的“支持 JS 的浏览器错误”agent.user_agent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0)

标签: javascript ruby-on-rails ruby web-scraping


【解决方案1】:

要以编程方式与需要 Javascript 以实现核心功能的页面进行交互,您需要使用“无头浏览器”。

您应该查看WatirSeleniumphantomjs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-07
    • 2016-10-14
    • 1970-01-01
    • 2014-05-23
    • 2022-12-09
    • 2019-06-19
    相关资源
    最近更新 更多