scrapy splash:mouse_click无法打开弹出窗口

zhte4eai  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(134)

我正在试着从townwork(一个日本的工作信息网站)上抓取兼职工作信息。为了获得地址,我想打开一个弹出窗口。然后我开始使用Splash。虽然我可以使用splash:mouse_click打开其他链接和弹出窗口,但我无法打开所需的弹出窗口。
如有任何答复,我们将不胜感激。

要单击的链接。

预期结果。

目标页URLhttps://townwork.net/detail/clc_2578209001/joid_Y00BKDF4/
代码

function main(splash, args)
  assert(splash:go(args.url))
  local map = splash:select('#jsi-inflow-target > div > dl:nth-child(3) > dd > p > span > a')

  local bounds = map:bounds()
  local x_dif = bounds.right - bounds.left

  assert(map:mouse_click({x=bounds.width/3, y=bounds.height/3}))
  splash:wait(1)
  return {
    html = splash:html(),
    png = splash:png(),
    bounds = bounds

  }
end
e0bqpujr

e0bqpujr1#

我认为这个弹出窗口打开的速度才是问题所在。
我找到了另一个解决方案,而不是打开一个弹出页面来获取地址:从第一页得到纬度和经度。

def parse(self, response):
  dt_list = response.css('dt')
    for dt in dt_list:
      if dt.css('::text').get == "勤務地":
        a_tag = BeautifulSoup(dt.xpath('./following-sibling::dd').get()).find('a')
        if a_tag is None:
          continue
        item['lat'] = a_tag['data-lat']
        item['lon'] = a_tag['data-lon']

相关问题