我想用selenium和python对一些帖子发表评论。
这是我的密码:
html=driver.page_source
soup=BeautifulSoup(html,"html.parser")
input=soup.find_element_by_css_selector("body > div._2dDPU.CkGkG > div.zZYga > div > article > div.eo2As > section.sH9wk._JgwE > div > form > textarea)
input.clear()
input.send_keys("blahblah")
input.submit()
以下是错误消息:
TypeError Traceback (most recent call last)
<ipython-input-93-250a282801db> in <module>
----> 1 input=soup.find_element_by_css_selector("body > div._2dDPU.CkGkG > div.zZYga > div > article > div.eo2As > section.sH9wk._JgwE > div > form > textarea")
2 input.clear()
TypeError: 'NoneType' object is not callable
根据代码行:
soup
是beautifulsoup类型的对象,表示数据结构中的文档其中as^{} 是WebDriver/WebElement方法
因此,您将无法调用
soup
上的find_element_by_css_selector()
,这是一个美化组类型的对象。因此,您会看到错误:理想情况下,您需要在WebDriver实例上调用
find_element_by_css_selector()
,如下所示:相关问题 更多 >
编程相关推荐