简体   繁体   English

Selenium + bs4 在抓取之前选择正确的数据

[英]Selenium + bs4 choosing right data before scraping it

I want to scrape a data from this site https://www.marketbeat.com/insider-trades/ceo-share-buys-and-sales/ .我想从这个站点https://www.marketbeat.com/insider-trades/ceo-share-buys-and-sales/抓取数据。 Problem is i want to choose some options before scraping问题是我想在抓取之前选择一些选项

在此处输入图像描述

In the Country button i want to check every button在“国家/地区”按钮中,我想检查每个按钮

This is default state这是默认 state

在此处输入图像描述

After scraping data i want to repeat this process but with抓取数据后,我想重复这个过程,但是

Transaction type Sold shares checked交易类型 已售股票已勾选

For now i have https://colab.research.google.com/drive/1VUVSI5BGiN5lCFrj4WGfJaZg1-wtU2f1?usp=sharing现在我有https://colab.research.google.com/drive/1VUVSI5BGiN5lCFrj4WGfJaZg1-wtU2f1?usp=sharing

If someone could give me some hints i would apprecate that thanks如果有人能给我一些提示,我将不胜感激,谢谢

This should work.这应该有效。 You have to click the labels rather than the checkboxes您必须单击标签而不是复选框

dropdownButton = driver.find_element(By.ID, 'dropdownCountry');
dropdownButton.click();

dropdownList = driver.find_element(By.XPATH, '//ul[@aria-labelledby="dropdownCountry"]')
countryButtons = dropdownList.find_elements(By.TAG_NAME, "label");
countryButtons.pop(0)
for i in countryButtons:
    i.click()

soldSharesButton = driver.find_element(By.XPATH, '//option[@value="Sell"]')
soldSharesButton.click()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM