小编Mez*_*ith的帖子

如何用Selenium找到物体?

这是我的代码,我正在改变,修复,尝试另一个模块,但仍然无法得到我的div文本提取响应.

import selenium 
from selenium import webdriver

driver = 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();
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用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'
Run Code Online (Sandbox Code Playgroud)

Aftter一个小修复,我使用这个:

import selenium 
from selenium import webdriver

driver = webdriver.Firefox() 
driver.get('http://www.helloworld.com/')
element = driver.find_element_by_id('main')
main_text = element.text
Run Code Online (Sandbox Code Playgroud)

print element.textshell中的响应是:

Traceback(最近一次调用最后一次):

  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'] …
Run Code Online (Sandbox Code Playgroud)

python selenium python-2.7

1
推荐指数
1
解决办法
1万
查看次数

来自使用Firefox的网站的BeautifulSoup和div值

经过一些改变,我得到了:

import urllib2
from bs4 import BeautifulSoup

soup = BeautifulSoup(urllib2.urlopen("http://example.com"))

soup.find("div", {"id": "botloc"})

elem = soup.find('div')
print elem['id'], 'is the id'
print elem.text, 'is the value'
Run Code Online (Sandbox Code Playgroud)

所以最后我写了正确的代码(有论坛帮助),但回复的价值是错误的,因为它从谷歌chrome获取它!任何想法如何从Firefox获得div值?(我在firefox浏览器上的服务器上)我赞成每个提示

python beautifulsoup python-2.7

0
推荐指数
1
解决办法
118
查看次数

标签 统计

python ×2

python-2.7 ×2

beautifulsoup ×1

selenium ×1