Parse PMDA table-based pages (safety info, precautions, alerts).
(self, html: str, base_url: str)
| 2118 | return None |
| 2119 | |
| 2120 | def _parse_table_page(self, html: str, base_url: str) -> list[dict]: |
| 2121 | """Parse PMDA table-based pages (safety info, precautions, alerts).""" |
| 2122 | results = [] |
| 2123 | try: |
| 2124 | from bs4 import BeautifulSoup |
| 2125 | soup = BeautifulSoup(html, "html.parser") |
| 2126 | for tr in soup.find_all("tr"): |
| 2127 | cells = tr.find_all("td") |
| 2128 | if len(cells) < 2: |
| 2129 | continue |
| 2130 | date_text = "" |
| 2131 | content_title = "" |
| 2132 | link_title = "" |
| 2133 | link_href = "" |
| 2134 | for cell in cells: |
| 2135 | cell_text = cell.get_text(strip=True) |
| 2136 | dm = re.search(r"((?:January|February|March|April|May|June|July|August|September|October|November|December)\s+\d{1,2},?\s*\d{4})", cell_text) |
| 2137 | if not dm: |
| 2138 | dm = re.search(r"((?:January|February|March|April|May|June|July|August|September|October|November|December)\s+\d{4})", cell_text) |
| 2139 | if not dm: |
| 2140 | dm = re.search(r"(\d{4})[./\-](\d{1,2})[./\-](\d{1,2})", cell_text) |
| 2141 | if dm and not date_text: |
| 2142 | if dm.lastindex and dm.lastindex >= 2: |
| 2143 | date_text = f"{dm.group(1)}-{dm.group(2).zfill(2)}-{dm.group(3).zfill(2)}" |
| 2144 | else: |
| 2145 | date_text = dm.group(1) |
| 2146 | a = cell.find("a") |
| 2147 | if a and a.get_text(strip=True) and len(a.get_text(strip=True)) > 5: |
| 2148 | link_title = a.get_text(strip=True) |
| 2149 | link_href = a.get("href", "") |
| 2150 | elif len(cell_text) > 5 and not re.match(r"^[\d\s,./]+$", cell_text) and not content_title: |
| 2151 | if cell_text != date_text and not re.search(r"^\d+$", cell_text): |
| 2152 | content_title = cell_text |
| 2153 | title_text = content_title or link_title |
| 2154 | if not title_text or len(title_text) < 5: |
| 2155 | continue |
| 2156 | title_text = re.sub(r"\s*\[\d+\s*KB\]", "", title_text).strip() |
| 2157 | if re.match(r"^(?:January|February|March|April|May|June|July|August|September|October|November|December)\s*\d{4}$", title_text): |
| 2158 | continue |
| 2159 | if link_href and not link_href.startswith("http"): |
| 2160 | link_href = "https://www.pmda.go.jp" + link_href |
| 2161 | results.append({ |
| 2162 | "title": title_text, |
| 2163 | "link": link_href, |
| 2164 | "pub_date": date_text, |
| 2165 | "description": "", |
| 2166 | }) |
| 2167 | if not results: |
| 2168 | for li in soup.select("ul li, .whatsnew li, dl dt, dl dd"): |
| 2169 | links = li.find_all("a") |
| 2170 | for a in links: |
| 2171 | title = a.get_text(strip=True) |
| 2172 | href = a.get("href", "") |
| 2173 | if not title or len(title) < 10: |
| 2174 | continue |
| 2175 | if href and not href.startswith("http"): |
| 2176 | href = "https://www.pmda.go.jp" + href |
| 2177 | dm = re.search(r"(\d{4})[./\-](\d{1,2})[./\-](\d{1,2})", li.get_text()) |