正在获取网页,但需要javascript来查看页面内容

正在获取网页,但需要javascript来查看页面内容,javascript,python,selenium,mechanize,Javascript,Python,Selenium,Mechanize,从网站获取数据/表单时,我尝试了机械化和selenium,都失败了 机械化 脚本如下所示 import sys import mechanize url ='xxx' response2=br.open(url) request = br.request print (response2.info()) print (response2.read()) 输出: Cache-Control: no-store, must-revalidate, no-cache, max-age=0 Conte

从网站获取数据/表单时,我尝试了机械化和selenium,都失败了

机械化 脚本如下所示

import sys
import mechanize
url ='xxx'
response2=br.open(url)
request = br.request
print (response2.info())
print (response2.read())
输出:

Cache-Control: no-store, must-revalidate, no-cache, max-age=0
Content-Type: text/html
Connection: close
Vary: Accept-Encoding
Pragma: no-cache
Expires: -1
CacheControl: no-cache
X-UA-Compatible: IE=edge
Content-Type: text/html; charset=utf-8

... more content ...

<noscript>Please enable JavaScript to view the page content.</noscript>
</head><body>
</body></html>
但是我又失败了,结果几乎是一样的:

...
<noscript>Please enable JavaScript to view the page content.</noscript>
...
。。。
请启用JavaScript以查看页面内容。
...
我只想从站点获取正确的内容/表单,然后
提交
发布
数据/表单到服务器,以模拟web浏览器访问操作

我现在没有想法,我不知道硒是如何工作的,等待您的帮助,提前谢谢

试试这个:
使用以下配置文件启用闪存

from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

firefoxProfile = FirefoxProfile()

## Enable Flash

firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',
                          'true')

driver = webdriver.Firefox(firefoxProfile)
如果使用chromedriver而不是firefox仍然不起作用,那么默认情况下它似乎在chromedriver中起作用


对不起,忘记了url,url是
https://onlineservices.immigration.govt.nz/?WHS
能否尝试添加此..profile=webdriver.FirefoxProfile()..profile.set_首选项(“javascript.enabled”,True..broswer=webdriver.Firefox(profile)当我访问该页面时,他们会向我显示一个图像代码,以防止非人类访问者。显然,他们不希望您获取该数据。@codeiscool有人也找到了图像代码,但我没有看到它。我不知道为什么。可能他们有一个图像代码的IP筛选器。
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

firefoxProfile = FirefoxProfile()

## Enable Flash

firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',
                          'true')

driver = webdriver.Firefox(firefoxProfile)