使用硒的Python网络抓取表

时间:2019-07-06 19:49:45

标签: python html css

我刚刚在公司的个人项目上进行网络爬取,直到现在还可以,我试图从该表中获取仅带有红点的行的文本。

我放置了来自meraki现场演示的源代码中的链接,因为需要登录才能查看我在说的表。

已经设法使用硒抓取页面并转到我想要的位置,我只是无法仅从带有红点的行中获取数据。

我要过滤的红点:

img style =“ margin-bottom:1px” src =“ / images / bubble-shadow-red.png” height =“ 20px” width =“ 20px”

在代码中,我仅设法获得带有绿点的示例:

img style =“ margin-bottom:1px” src =“ / images / bubble-shadow-1.png” height =“ 20px” width =“ 20px”

表代码 https://github.com/Solomonrp/Merakicase/blob/master/Case

这所有的页面代码: https://github.com/Solomonrp/Merakicase/blob/master/All%20code

I put a picture from the table that I'm talking

设法获取数据,但是现在我正在尝试使src进行过滤,如果图片是绿色还是红色:

row_conta = len(browser.find_elements_by_xpath("//*[@id='row_0']"))
col_conta = len(browser.find_elements_by_xpath("//*[@id='row_0']/td"))
print("number of rows",row_conta)
print("number of  col", col_conta)
first = "//*[@id='row_"
second = "']/td["
third = "]"

#trying to get the src ()failling)
images = browser.find_elements_by_tag_name("img")
im = images.get_attribute('src')

n = 0
while(n <35):
  n = n+1
  m = 1
  while(m <10):
      if "red" in im: #trying to check the src
        final = first+str(n)+second+str(m)+third
        tablea = browser.find_element_by_xpath(final).text
        print(tablea) 
        m=m+1

0 个答案:

没有答案
相关问题