动态(带有鼠标/坐标)Web刮擦Python无法提取信息

发布于 2025-01-29 08:21:15 字数 2129 浏览 2 评论 0原文

我正在尝试刮擦仅在鼠标上出现的数据(硒)。这是一张音乐会地图,这是我的整个代码。我不断获得TypeError:“ ActionChains”对象是不可能的,

想法是悬停在整个地图上& HTML更改时始终刮擦代码。我很确定我需要两个循环,但是我还不知道,如何结合它们。另外,我知道我必须使用BS4,有人可以分享想法如何解决这个问题吗?

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://www.ticketcorner.ch/event/simple-minds-hallenstadion-12035377/')

#accept shadow-root cookie banner

time.sleep(5)
driver.execute_script('return document.querySelector("#cmpwrapper").shadowRoot.querySelector("#cmpbntyestxt")').click()
time.sleep(5)

# Click on the saalplan so we get to the concert map

WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, '#tickets > div.seat-switch-wrapper.js-tab-switch-group > a:nth-child(3) > div > div.seat-switch-radio.styled-checkbox.theme-switch-bg.theme-text-color.theme-link-color-hover.theme-switch-border > label'))).click()
time.sleep(5)

#Scroll to the concert map, which will be the element to hover over

element_map = driver.find_element(By.CLASS_NAME, 'js-tickettype-cta')
actions = ActionChains(driver)
actions.move_to_element(element_map).perform()

# Close the drop-down which is partially hiding the concert map

driver.find_element(by=By.XPATH, value='//*[@id="seatmap-tab"]/div[2]/div/div/section/div[2]/div[1]/div[1]/div/div/div[1]/div').click()


# Mouse Hover over the concert map and find the empty seats to extract the data.

actions = ActionChains(driver)
data = actions.move_to_element_with_offset(driver.find_element(by=By.XPATH, value='//*[@id="seatmap-tab"]/div[2]/div/div/section/div[2]/div[1]/div[2]/div/div[2]/div[1]/div[2]/div[2]/canvas'),0,0)
for i in data:
    actions.move_by_offset(50, 50).perform()
    time.sleep(2)
    # print content of each box
    hover_data = driver.find_element(By.XPATH, '//*[@id="tooltipster-533522"]/div[1]').get_attribute('tooltipster-content')
    print(hover_data)```

# The code I would use to hover over the element
    #actions.move_by_offset(100, 50).perform()
    # time.sleep(5)
    # actions.move_by_offset(150, 50).perform()
    # time.sleep(5)
    # actions.move_by_offset(200, 50).perform()

I'm trying to scrape the data that only appears on mouseover(selenium). It's a concert map and this is my entire code. I keep getting TypeError: 'ActionChains' object is not iterable

The idea would be to hover over the whole map & always scrape the code when the html changes. I'm pretty sure I need two for loops for that, but I don't know yet, how to combine them. Also, I know I'll have to use bs4, could someone share ideas how I could go about this?

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://www.ticketcorner.ch/event/simple-minds-hallenstadion-12035377/')

#accept shadow-root cookie banner

time.sleep(5)
driver.execute_script('return document.querySelector("#cmpwrapper").shadowRoot.querySelector("#cmpbntyestxt")').click()
time.sleep(5)

# Click on the saalplan so we get to the concert map

WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, '#tickets > div.seat-switch-wrapper.js-tab-switch-group > a:nth-child(3) > div > div.seat-switch-radio.styled-checkbox.theme-switch-bg.theme-text-color.theme-link-color-hover.theme-switch-border > label'))).click()
time.sleep(5)

#Scroll to the concert map, which will be the element to hover over

element_map = driver.find_element(By.CLASS_NAME, 'js-tickettype-cta')
actions = ActionChains(driver)
actions.move_to_element(element_map).perform()

# Close the drop-down which is partially hiding the concert map

driver.find_element(by=By.XPATH, value='//*[@id="seatmap-tab"]/div[2]/div/div/section/div[2]/div[1]/div[1]/div/div/div[1]/div').click()


# Mouse Hover over the concert map and find the empty seats to extract the data.

actions = ActionChains(driver)
data = actions.move_to_element_with_offset(driver.find_element(by=By.XPATH, value='//*[@id="seatmap-tab"]/div[2]/div/div/section/div[2]/div[1]/div[2]/div/div[2]/div[1]/div[2]/div[2]/canvas'),0,0)
for i in data:
    actions.move_by_offset(50, 50).perform()
    time.sleep(2)
    # print content of each box
    hover_data = driver.find_element(By.XPATH, '//*[@id="tooltipster-533522"]/div[1]').get_attribute('tooltipster-content')
    print(hover_data)```

# The code I would use to hover over the element
    #actions.move_by_offset(100, 50).perform()
    # time.sleep(5)
    # actions.move_by_offset(150, 50).perform()
    # time.sleep(5)
    # actions.move_by_offset(200, 50).perform()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文