多数民众赞成在我的代码,我正在更改,修复,尝试其他模块,但仍无法获得提取的div文本的响应。import selenium from selenium import webdriverdriver = webdriver.Firefox() driver.get('http://www.helloworld.com/')element = driver.find_element_by_id('main')WebElement = driver.findElement(By.xpath("//div[@class='main']"));webElement.getText();我正在尝试使用bs4软件包,但是有一个大问题,因为仅当我登录网站时,我想要的数据才可能获得,并且在bs4中的响应就像来自来宾帐户一样,而无需登录。这是Traceback我使用Selenium获得的代码:Traceback (most recent call last): File "D:/Python27/get text value div.py", line 8, in <module> WebElement = driver.findElement(By.xpath("//div[@class='main']"));AttributeError: 'WebDriver' object has no attribute 'findElement'之后的一个小解决方案,我正在使用此:import selenium from selenium import webdriverdriver = webdriver.Firefox() driver.get('http://www.helloworld.com/')element = driver.find_element_by_id('main')main_text = element.textprint element.textshell中的响应为:追溯(最近一次通话): File "<pyshell#20>", line 1, in <module> element.text File "D:\Python27\lib\selenium\webdriver\remote\webelement.py", line 50, in text return self._execute(Command.GET_ELEMENT_TEXT)['value'] File "D:\Python27\lib\selenium\webdriver\remote\webelement.py", line 228, in _execute return self._parent.execute(command, params) File "D:\Python27\lib\selenium\webdriver\remote\webdriver.py", line 165, in execute self.error_handler.check_response(response) File "D:\Python27\lib\selenium\webdriver\remote\errorhandler.py", line 152, in check_response raise exception_class(message, screen, stacktrace)WebDriverException: Message: u'\'[JavaScript Error: "a is null" {file: "file:///c:/dokume~1/tomek/lokale%20einstellungen/temp/tmpupvgr2/extensions/fxdriver@googlecode.com/components/command_processor.js" line: 7623}]\' when calling method: [nsICommandProcessor::execute]'
添加回答
举报
0/150
提交
取消