Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
按类获取图像并单击UsingSeleniumPython_Python_Selenium - Fatal编程技术网

按类获取图像并单击UsingSeleniumPython

按类获取图像并单击UsingSeleniumPython,python,selenium,Python,Selenium,我试图从图像类profile_view_img_5087188中获取所有图像,但在页面源中有多个类“profile_view_img_xxxxxx”,其中包含相同图像url的类更少 http://i.imgur.com/oraB49H.png 我想单击上面的图像url是否找到 <head><style type="text/css">.profile_view_img_5087188 { background-image: url('http://i.imgur.com

我试图从图像类profile_view_img_5087188中获取所有图像,但在页面源中有多个类“profile_view_img_xxxxxx”,其中包含相同图像url的类更少

http://i.imgur.com/oraB49H.png
我想单击上面的图像url是否找到

<head><style type="text/css">.profile_view_img_5087188 { background-image: url('http://i.imgur.com/oraB49H.png'); }</style></head>



<a class="cursor earn_pages_button profile_view_img_5087188" onclick="startlink52efa('newlookskincenter','follow','99218',16837);imageWin('http://instagram.com/newlookskincenter','Instagram','99218','newlookskincenter','qFVnV5xlY2OJaW4','1015','500','follow',16837)"></a>

首先,您需要获得所有的
标记,这些标记具有classname
profile\u view\u img\u 5087188
编号不同。因此,使用以下xpath获取所有标记:

like_button = browser.find_elements_by_xpath("//a[contains(@class,'profile_view_img')]")
然后在所有链接中循环并在中找到您的图像url

for links in like_button:
if "http://instagram.com/newlookskincenter" in link.get_attribute('onclick'):
  links.click()

注意:请确保您使用了正确的字符串比较,因为我对python语法不太了解

我在上面提供的标记中没有看到任何
href
属性,您可以添加一些有助于进一步澄清的html吗图像源在样式表中..profile_view_img5087188{background image:url(');}@Bostan,试试这个答案,如果有的话请告诉我issue@Bostan继续聊天讨论
for links in like_button:
if "http://instagram.com/newlookskincenter" in link.get_attribute('onclick'):
  links.click()