簡體   English   中英

Python,飛濺 select XPATH 然后點擊按鈕

[英]Python, Splash select XPATH and click button

我想使用 Python 和 Splash 到 select 帶有 XPATH 的“Ich stimme zu”按鈕,然后單擊。

我不能使用 CSS class 因為它有一個動態名稱。

URL: https://consent.google.com/m?continue=https://www.google.com/maps/search/Berlin%2Brestaurant/&gl=DE&m=0&pc=m&hl=de&src=1

有人可以幫我嗎?

function main(splash)
      local url = splash.args.url
      assert(splash:go(url))
      assert(splash:wait(0.5))
   
      bounds = selector:xpath("/html/body/c-wiz/div/div/div/div[2]/div[1]/div[4]/form/div/div").click()
        return {
        html = splash:html(),
        png = splash:png(),
        href=href,
      }
end

事實證明,我可以使用 CSS 完全正常地單擊按鈕 - 我已經在控制台上對其進行了測試。

看起來你正在嘗試將腳本與scrapy-splash集成,結果你得到的消息沒有出現在啟動控制台上。也許你正在嘗試它並且沒有按鈕因為你沒有意識到這一點?

無論如何 - 這是在控制台中對我有用的,我已經在 lua 腳本中更新了它:

function main(splash, args)
  assert(splash:go(args.url))
  local click_on = splash:jsfunc([[
    function(){
    document.querySelector("button[aria-label='Consent to the use of cookies and other data for the purposes described']").click()
  }
    ]])
  splash:wait(0.5)
  click_on()
  splash:wait(3)
  return {
    html = splash:html(),
    png = splash:png(),
    har = splash:har(),
  }
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM