【发布时间】:2017-03-09 01:40:18
【问题描述】:
我在执行我的 Python 程序时遇到以下错误,该程序尝试将 href 元素添加到基本 URL 以形成下一页的 URL:
"TypeError : 无法连接 'str' 和 'FirefoxWebElement' 对象"
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
my_url = 'http://cbseaff.nic.in/cbse_aff/schdir_Report/userview.aspx'
browser.get(my_url)
radio_key_word = browser.find_element_by_id("optlist_0")
radio_key_word.click()
time.sleep(6)
search = browser.find_element_by_id('keytext')
search.send_keys('0')
search.send_keys(Keys.RETURN)
search.clear()
time.sleep(6)
initial_url = 'http://cbseaff.nic.in/cbse_aff/schdir_Report/'
# links = browser.find_elements_by_xpath('//tr/td/a/@href')
links = browser.find_elements_by_xpath("//tr/td/a/@href")
print len(links)
for link in links:
# print str(link)
new_url = initial_url + link
print new_url
browser.close()
这是我在执行时遇到的错误:
C:\Python27\python.exe C:/Python_project/8_March_2017/test_subject.py
Traceback (most recent call last):
25
File "C:/Python_project/8_March_2017/test_subject.py", line 30, in <module>
new_url = initial_url + link
TypeError: cannot concatenate 'str' and 'FirefoxWebElement' objects
【问题讨论】:
-
您肯定需要提供更多信息,包括您正在执行的 HTML 以及您正在尝试做什么。
-
我已经更新了问题,你现在可以检查一下吗?
标签: python selenium-webdriver web-scraping