How do I scrape ::before element in a website using selenium python

后端 未结 2 594
没有蜡笔的小新
没有蜡笔的小新 2021-01-05 18:26

I am trying to scrape phone number from this website using selenium. I found the class to be \"tel ttel\" but when I try to scrape the website by find_element_by_xpath. I ge

2条回答
  •  佛祖请我去吃肉
    2021-01-05 18:50

    You can also get the :before content from the computed style:

    chars = driver.execute_script("return [...document.querySelectorAll('.telCntct a.tel span')].map(span => window.getComputedStyle(span,':before').content)")
    

    But in this case you're left with weird unicode content that you then have to map to numbers.

提交回复
热议问题