Hi Gumloop Community,
I’m using the “Run Code” node to scrape meta-titles and meta-descriptions from URLs of webpages, but I’m getting this error:
Loading https://shop.mmtcpamp.com/silver/silver-coin
https://www.tanishq.co.in/product/10-gram-999-purity-silver-coin-800102zlaaba00.html from storage.
Run Code Failed!
There was an error in your Run Code node.
def function(gettitle_desc):
import requests
from bs4 import BeautifulSoup
urls = gettitle_desc.split(",")
urls = [url.strip() for url in urls]
results = []
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"}
for url in urls:
try:
response = requests.get(url, headers=headers, timeout=10)
if response.status_code == 200:
soup = BeautifulSoup(response.content, 'html.parser')
meta_title = soup.title.string if soup.title else "Not found"
meta_description_tag = soup.find("meta", attrs={"name": "description"})
meta_description = meta_description_tag["content"] if meta_description_tag else "Not found"
else:
meta_title = "Error"
meta_description = f"HTTP Error {response.status_code}"
results.append({"url": url, "meta_title": meta_title, "meta_description": meta_description})
except Exception as e:
results.append({"url": url, "meta_title": "Error", "meta_description": f"Error: {str(e)}"})
return results
Setup:
- Input: gettitle_desc mapped to data[0].Urls List from “Google Sheets Reader”.
- Output: results.
I suspect the error is due to missing requests and beautifulsoup4 libraries. Are these available in the “Run Code” node? If not, how can I request them? Should I use the “Web Agent Scraper” node instead?
Appreciate your help . Thanks!
Sharing my workbook with you guys
https://www.gumloop.com/pipeline?workbook_id=jrK1CgR8bQao9FP6sLV7i9