简体   繁体   English

使用Selenium的python中的WebScraping问题

[英]WebScraping issues in python using Selenium

I'm trying to scrape data from this website called Anhembi 我正在尝试从这个名为Anhembi的网站上抓取数据

But when I try all the options from selenium to find elements, I get nothing. 但是,当我尝试使用硒中的所有选项来查找元素时,我什么也没得到。 Anyone know why this happens? 有人知道为什么会这样吗?

I've already tried: 我已经尝试过:

driver.find_element_by_xpath('//*[@class="agenda_result_laco_box"]') 

And made a for-loop through that to click in every single one and get the info I need which consists of the day, website and name of the events. 并在其中for-loop了一个for-loop ,单击每个for-loop并获取我需要的信息,其中包括日期,网站和事件名称。 How can I do that? 我怎样才能做到这一点?

Clearly, there is an iframe involved , you need to switch the focus of your web driver in order to interact with elements which are in iframe/frameset/frame . 显然,其中涉及一个iframe ,您需要切换Web驱动程序的焦点才能与iframe/frameset/frame元素进行交互。

You can try with this code : 您可以尝试使用以下代码

driver.get("http://www.anhembi.com.br/agenda/") 

driver.switch_to.frame(driver.find_element_by_css_selector("iframe[src='http://intranet.spturis.com.br/intranet/modulos/booking/anhembisite_busca.php']"))
all_data = driver.find_elements_by_css_selector("div.agenda_result_laco_box")

print(len(all_data))

for data in all_data:
  print(data.text)

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

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