简体   繁体   English

如何通过 find_element_by_xpath 来 select div class?

[英]how to select div class by find_element_by_xpath?

I'm making instagram like bot, but I can not find the element for the post in #tag page.我正在制作类似机器人的 instagram,但在#tag 页面中找不到帖子的元素。

enter image description here在此处输入图像描述

Red circle is what I want to click it, and the inspected element is enter image description here红圈是我要点击的,被检查的元素是在此处输入图像描述

my code is我的代码是

e = driver.find_element_by_xpath('/html/body/div[1]/section/main/article/div[2]/div/div[1]/div[1]/a/div/div[2]')

e.click()

but it didn't work.但它没有用。 how do I select this element?我怎么select这个元素?

Ok, first, you need to know that, the inspection you're doing on your chrome is not going to be the same when running a new instance of your program due to generated css class, so that can be the first problem, The second problem is that.好的,首先,您需要知道,由于生成的 css class,在运行程序的新实例时,您在 chrome 上进行的检查不会相同,所以这可能是第一个问题,第二个问题是这样的。 it's possible you just got blocked by instagram because you're it detected that you're not a 'real' browser.您可能刚刚被 instagram 阻止,因为它检测到您不是“真正的”浏览器。

There can be many reasons, So first, make sure you can get the whole html and it has the same structure as the one you're trying to fetch/scrap !可能有很多原因,所以首先,请确保您可以获得整个 html 并且它与您尝试获取/报废的结构相同!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM