【发布时间】:2018-11-27 14:44:59
【问题描述】:
我想使用带有 Selenium 的 Python 提交评论。 Instagram 网页中的评论框如下所示:
<textarea aria-label="Añade un comentario..." placeholder="Añade un comentario..." class="Ypffh" autocomplete="off" autocorrect="off" style="height: 18px;"></textarea>
我的 Python 代码:
coment_box = driver.find_elements_by_css_selector("form textarea")
coment_box.send_keys("Nice picture")
我尝试使用find_by_xpath("here_xpath"),但它返回一个错误,提示:AttributeError: 'list' object has no attribute 'send_keys'。
【问题讨论】:
-
您可以使用以下 CSS 选择器:
.Ypffh. -
它说 AttributeError: 'list' object has no attribute 'send_keys'
-
所以,你需要改用
find_element_by_css_selector。 -
如果我使用comment_box.find_element_by_css_selector(".Ypffh") 和comment_box.send_keys("Hello") 返回之前提到的错误
-
不可能,因为
find_element_by_css_selector会返回1个网页元素。
标签: python html selenium instagram