Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想在instagram中用Python中的selenium webdriver发表评论_Python_Selenium_Automation_Bots_Instagram - Fatal编程技术网

我想在instagram中用Python中的selenium webdriver发表评论

我想在instagram中用Python中的selenium webdriver发表评论,python,selenium,automation,bots,instagram,Python,Selenium,Automation,Bots,Instagram,我的代码是: comments_to_like = driver.find_elements_by_class_name('_8-yf5 ') time.sleep(5) n += 1 x = 0 for each in range(len(comments_to_like)): liked = random.choice(comments_to_like) time.sleep(5) ActionChains(driver).move_to_element(comm

我的代码是:

comments_to_like = driver.find_elements_by_class_name('_8-yf5 ')
time.sleep(5)

n += 1
x = 0
for each in range(len(comments_to_like)):
    liked = random.choice(comments_to_like)
    time.sleep(5)

    ActionChains(driver).move_to_element(comments_to_like[each]).click(comments_to_like[each]).perform()
我试着用action chain,但不确定这是否有帮助

这是Instagram的dom

<div class="QBdPU ">
    <span class="">
        <svg aria-label="Like" class="_8-yf5 " fill="#262626" height="12" viewBox="0 0 48 48" width="12">
            <path d="M34.6 6.1c5.7 0 10.4 5.2 10.4 11.5 0 6.8-5.9 11-11.5 16S25 41.3 24 41.9c-1.1-.7-4.7-4-9.5-8.3-5.7-5-11.5-9.2-11.5-16C3 11.3 7.7 6.1 13.4 6.1c4.2 0 6.5 2 8.1 4.3 1.9 2.6 2.2 3.9 2.5 3.9.3 0 .6-1.3 2.5-3.9 1.6-2.3 3.9-4.3 8.1-4.3m0-3c-4.5 0-7.9 1.8-10.6 5.6-2.7-3.7-6.1-5.5-10.6-5.5C6 3.1 0 9.6 0 17.6c0 7.3 5.4 12 10.6 16.5.6.5 1.3 1.1 1.9 1.7l2.3 2c4.4 3.9 6.6 5.9 7.6 6.5.5.3 1.1.5 1.6.5.6 0 1.1-.2 1.6-.5 1-.6 2.8-2.2 7.8-6.8l2-1.8c.7-.6 1.3-1.2 2-1.7C42.7 29.6 48 25 48 17.6c0-8-6-14.5-13.4-14.5z"></path>
        </svg>
    </span>
</div>


我需要喜欢这些注释,但不确定如何做才有帮助。

我不确定在这种情况下按类选择是否是个好主意,因为类名看起来像是随机生成的名称

一致:

ActionChains(driver).move_to_element(comments_to_like[each]).click(comments_to_like[each]).perform()
你应该这样做(但我不是100%确定它是否有效):

或者你可以这样重写它:

all_svg=driver.find_elements_by_tag_name("svg")

for svg in all_svg:
    if svg.get_attribute("aria-label") == "Like":
        svg.click()

感谢您的工作,但现在我有MoveTargetOutOfBoundsException来自selenium的任何建议,它有一些模式代码来处理此异常。我正在使用Firefoxwebdriver@MikeHadzhiev.move_to_element()失败并引发MoveTargetAutofBoundsException,请尝试以其他方式单击它,您可以尝试:
comments_to_like[each]。单击()
而不是
操作链(驱动程序)。将\u移动到\u元素(注释到\u,如[每个])。单击()。执行()
all_svg=driver.find_elements_by_tag_name("svg")

for svg in all_svg:
    if svg.get_attribute("aria-label") == "Like":
        svg.click()