| 52 | |
| 53 | |
| 54 | def get_image_urls(query): |
| 55 | try: |
| 56 | search_url = f"https://www.google.com/search?q={query}&tbm=isch" |
| 57 | image_response = requests.get(search_url) |
| 58 | image_response.raise_for_status() |
| 59 | image_soup = BeautifulSoup(image_response.content, "html.parser") |
| 60 | |
| 61 | image_urls = [] |
| 62 | for img in image_soup.find_all("img"): |
| 63 | image_url = img.get("src") |
| 64 | if image_url and image_url.startswith("http"): |
| 65 | image_urls.append(image_url) |
| 66 | |
| 67 | return image_urls[0] |
| 68 | |
| 69 | except requests.exceptions.RequestException as e: |
| 70 | print("Error fetching image URLs:", e) |
| 71 | return None |