[英]Python Selenium - get href
I want to get some links in the url but they I get all links instead.我想在 url 中获得一些链接,但我得到了所有链接。 How can I pull the links by specifying the selector?
如何通过指定选择器来拉取链接?
For ex:例如:
I'm using:我在用着:
ids = browser.find_elements_by_xpath('//a[@href]')
for ii in ids:
print(ii.get_attribute('href'))
Result: All Links结果:所有链接
But I want just some selector但我只想要一些选择器
<a class="classifiedTitle" title="MONSTER TULPAR T5V13.1+ 15,6 EKRAN+İ7+6GB GTX1060+16RAM+256GB SS" href="/ilan/ikinci-el-ve-sifir-alisveris-bilgisayar-dizustu-notebook-monster-tulpar-t5v13.1-plus-15%2C6-ekran-plusi7-plus6gb-gtx1060-plus16ram-plus256gb-ss-793070526/detay">
MONSTER TULPAR T5V13.1+ 15,6 EKRAN+İ7+6GB GTX1060+16RAM+256GB SS</a>
So how can I add some selectors?那么如何添加一些选择器呢?
Thanks & Regards感谢和问候
If you want just the item in your example:如果您只想要示例中的项目:
href=browser.find_element_by_xpath("//a[@title='MONSTER TULPAR T5V13.1+ 15,6 EKRAN+İ7+6GB GTX1060+16RAM+256GB SS" href="/ilan/ikinci-el-ve-sifir-alisveris-bilgisayar-dizustu-notebook-monster-tulpar-t5v13.1-plus-15%2C6-ekran-plusi7-plus6gb-gtx1060-plus16ram-plus256gb-ss-793070526/detay']").get_attribute('href')
There are obviously more than one way of identifying your element, this is simply an example using xpath
.显然有不止一种方法可以识别您的元素,这只是一个使用
xpath
的示例。
Try the following css
selector to get the specific link.试试下面的
css
选择器获取具体链接。
print(browser.find_element_by_css_selector("a.classifiedTitle[title='MONSTER TULPAR T5V13.1+ 15,6 EKRAN+İ7+6GB GTX1060+16RAM+256GB SS'][href*='/ilan/ikinci-el-ve-sifir-alisveris-bilgisayar-dizustu-notebook-monster-tulpar-']").get_attribute("href"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.