Extract direct image URL from a Wikipedia file information page.
(url)
| 340 | |
| 341 | |
| 342 | def get_wikipedia_image(url): |
| 343 | """Extract direct image URL from a Wikipedia file information page.""" |
| 344 | try: |
| 345 | response = requests.get(url, timeout=5) |
| 346 | response.raise_for_status() |
| 347 | soup = BeautifulSoup(response.text, 'html.parser') |
| 348 | image_tag = soup.find('div', class_='fullImageLink') |
| 349 | if image_tag: |
| 350 | image_link = image_tag.find('a') |
| 351 | if image_link and 'href' in image_link.attrs: |
| 352 | return urljoin(url, image_link['href']) |
| 353 | except requests.RequestException as e: |
| 354 | prRed(f"Failed to get direct Wikipedia image URL from {url}: {e}") |
| 355 | return None |
| 356 | |
| 357 | |
| 358 | def is_valid_url(url): |
no test coverage detected