[release_table] Support JavaScript rendering (#327)
Based on the render_javascript option.
This commit is contained in:
@@ -13,9 +13,13 @@ from liquid import Template
|
||||
This script works based on a definition provided in the product's frontmatter to locate the table and extract the
|
||||
necessary information. Available configuration options are:
|
||||
|
||||
- selector (mandatory, no default): A CSS selector used to locate one or more tables in the page.
|
||||
- selector (mandatory, no default): A CSS selector used to locate one or more tables in the page.
|
||||
- header_selector (mandatory, default = thead tr): A CSS selector used to locate the table's header row.
|
||||
- rows_selector (mandatory, default = tbody tr): A CSS selector used to locate the table's rows.
|
||||
- render_javascript (optional, default = false): A boolean value indicating whether to render JavaScript on the page.
|
||||
- ignore_empty_releases (optional, default = false): A boolean value indicating whether to ignore releases with no
|
||||
fields except the name.
|
||||
- fields: A dictionary that maps release fields to the table's columns. Field definition include:
|
||||
- column (mandatory): The name of the column in the table. This is case-insensitive.
|
||||
- type (mandatory, default = string): The type of the field. Supported types are:
|
||||
@@ -117,9 +121,7 @@ p_filter = sys.argv[1] if len(sys.argv) > 1 else None
|
||||
m_filter = sys.argv[2] if len(sys.argv) > 2 else None
|
||||
for config in endoflife.list_configs(p_filter, METHOD, m_filter):
|
||||
with releasedata.ProductData(config.product) as product_data:
|
||||
response = http.fetch_url(config.url)
|
||||
soup = BeautifulSoup(response.text, features="html5lib")
|
||||
|
||||
render_javascript = config.data.get("render_javascript", False)
|
||||
ignore_empty_releases = config.data.get("ignore_empty_releases", False)
|
||||
header_row_selector = config.data.get("header_selector", "thead tr")
|
||||
rows_selector = config.data.get("rows_selector", "tbody tr")
|
||||
@@ -127,6 +129,9 @@ for config in endoflife.list_configs(p_filter, METHOD, m_filter):
|
||||
release_cycle_field = Field("releaseCycle", config.data["fields"].pop("releaseCycle"))
|
||||
fields = [Field(name, definition) for name, definition in config.data["fields"].items()]
|
||||
|
||||
response_text = http.fetch_javascript_url(config.url) if render_javascript else http.fetch_url(config.url).text
|
||||
soup = BeautifulSoup(response_text, features="html5lib")
|
||||
|
||||
for table in soup.select(config.data["selector"]):
|
||||
header_row = table.select_one(header_row_selector)
|
||||
if not header_row:
|
||||
|
||||
Reference in New Issue
Block a user