繁体   English   中英

单击链接后,PhantomJS无法导航到下一页

[英]PhantomJS does not navigate to the next page after clicking a link

PhantomJS出现了一个奇怪的问题,或者可能是我是新手。 我正在尝试使用PhantomJS通过Selenium登录NewEgg.com。 我正在使用Python。 问题是,当我使用Firefox作为驱动程序时,它运行良好,但是一旦我将PhantomJS设置为驱动程序,它就不会进入下一页,因此显示以下消息:

Exception Message: u'{"errorMessage":"Unable to find element with id \'UserName\'","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"89","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:55372","User-Agent":"Python-urllib/2.7"},"httpVersion":"1.1","method":"POST","post":"{\\"using\\": \\"id\\", \\"sessionId\\": \\"aaff4c40-6aaa-11e4-9cb1-7b8841e74090\\", \\"value\\": \\"UserName\\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/aaff4c40-6aaa-11e4-9cb1-7b8841e74090/element"}}' ; Screenshot: available via screen 

我在截取屏幕快照后发现幻影无法导航页面且脚本完成的原因。 我该如何解决呢? 我尝试给出的代码片段如下:

从bs4导入请求从时间导入BeautifulSoup从硒导入休眠导入webdriver导入datetime

my_username = "user@mail.com"
my_password = "password"

driver = webdriver.PhantomJS('/Setups/phantomjs-1.9.7-macosx/bin/phantomjs')
firefox_profile = webdriver.FirefoxProfile()
#firefox_profile.set_preference('permissions.default.stylesheet', 2)
firefox_profile.set_preference('permissions.default.image', 2)
firefox_profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so', 'false')
#driver = webdriver.Firefox(firefox_profile)
driver.set_window_size(1120, 550)
driver.get('http://newegg.com')
driver.find_element_by_link_text('Log in or Register').click()
driver.save_screenshot('screen.png')

我什至sleep但没什么作用。

当第二页的内容类型不正确时,我在PhantomJS中遇到了这种情况。 普通的浏览器只是动态地解释内容,而Phantom只是死了,无声无息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM