JavaScript 使用 Python 和 Selenium 动态生成 html

Scraping dynamically generated html by JavaScript with Python and Selenium

我目前在动态生成的 html 代码方面遇到问题:

http://www.economia-sniim.gob.mx/Nuevo/Home.aspx?opcion=Consultas/MercadosNacionales/PreciosDeMercado/Agricolas/ConsultaFrutasYHortalizas.aspx?SubOpcion=4|0

我想在网站上选择“Origen”和“Date”选项,但我没有所有 HTML 代码。

谁能给我一个提示,如何 抓取 所有动态生成的 html 代码?

谢谢,

selenium 的优势在于您实际上可以从您的程序启动浏览器会话并在 javascript 中启用事件(如本例中的滚动)

In [8]: from bs4 import BeautifulSoup

In [9]: from selenium import webdriver

In [10]: driver = webdriver.Firefox()

In [11]: driver.get('http://cavemendev.com')

In [12]: html = driver.page_source

In [13]: soup = BeautifulSoup(html)

In [14]: driver.execute_script("window.scrollTo(0, Y)")

In [15]: for tag in soup.find_all('title'):
   ....:     print tag.text

让我知道如果没有多大意义