Ask coding questions

← Back to all posts
Call from Apps Script
HerreraCarlos81 (0)

Hello community

I have this python code which is supposed to make some scrapping and return the price of the item.

I want to call it using apps script with something like:

And return the output of the scrap as a result to the apps script which is running.

Is that possible? Anywhere I can read how to do it?

19ecal (228)

You can have a flask server like so

from flask import *
def scrape():
    #your code for scraping here
    return scraped_output
app=Flask ("main")
def main():
    return scrape()"")

Then you can fetch to that URL
It will be like this

19ecal (228)

So if you name the repl scrapingserver
You can fetch it at

HerreraCarlos81 (0)

@19ecal did a basic call to test it out but it only works inside, not when I call it from a browser with the url:

The result:

This site can’t be reached took too long to respond.

this is the new which I changed just to test the return

Any clues what I am doing wrong?

19ecal (228)

@HerreraCarlos81 are you using selenium or beautifulsoup

HerreraCarlos81 (0)

@19ecal I have made an attempt with both to figure out the best way to approach this scrapping, and both work fine until I add the flask server part. That is why I think the problem is with my set up of the server. If you run my selenium, it shows lots of errors

HerreraCarlos81 (0)

@HerreraCarlos81 I just figured out what I was missing and it works with beautifulsoup! Awesome. Will try to make same adjustment to see if I can get Selenium to work as well.

The problem was with my Python return code itself 🤦‍♂️, I hadn't noticed that before since I was just printing the result and not returning.

HerreraCarlos81 (0)

@19ecal Selenium fork still does not work 😥. I get a 500 error when trying to load on the browser while the flask server is running.

19ecal (228)

@HerreraCarlos81 You probably will have to stick with beautifulsoup then

HerreraCarlos81 (0)

@19ecal Got it. Thanks a lot for the support on the flask code.