html dom xpath,python - How to access HTML DOM Property using Xpath or Css Selector in Selenium - St...

Selenium ver 3.141. Chrome driver, Windows 10

Hello,

The objective is to extract the value of HTML DOM Property specifically the id,href and data-download-file-url for each of the images displayed from this website (Selection of this website is purely for educational purpose). While there exist other approach that can be applied to extract all these items, but at the time being, Im using the find_elements_by_xpath approach. Yet, I welcome if someone would like to suggest more efficient approach that I am not aware of.

From the aforementioned website, the Xpath to the target element is

/html/body/main/section[2]/div/div/figure[X]/div

with the capital X indicate the Image label that take the value from 1 to 50, for the aforementioned website. Each figure fall under the class showcase__content.

I tried the following lines

titles_element = browser.find_elements_by_xpath("//div[@class='showcase__content']/a")

# List Comprehension to get the actual repo titles and not the selenium objects.

titles = [x.text for x in titles_element]

However, there no dom properties extracted at the titles_element. Hence the titles produce [].

Im tempted to tried the following also but It give me an error instead

titles_element = browser.find_elements_by_xpath("//figure[1]/div[@class='showcase__content']//@data-download-file-url")

I really appreciate if someone can shed some light about this problem.

Example of the DOM property for Figure 1. The properties are all in pink color.

https://drive.google.com/open?id=190q615C3uXLZUQNI8K4AJYL3Slii1ktO

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值