cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

pyspark: How to run selenium in UDF

DievanB
New Contributor

Hi all,

I am building a webscraper to get prices of certain EAN's from the amazon website. Therefore I use selenium to get the product links. I wrote te following function to get the productlinks based on a EAN:

def getProductLinkAmazonPY(EAN):
  startURL = 'https://www.amazon.nl'
  driver.get(startURL)
  element = driver.find_element_by_id('twotabsearchtextbox')
  element.send_keys(EAN)
  element.send_keys(Keys.RETURN);
  productPage = [elem.get_attribute("href") for elem in driver.find_elements_by_xpath("//*[@class='a-link-normal a-text-normal']")] 
  if productPage != []:
    productPage = productPage[0]
    return[productPage, EAN]

Does somebody know how to run this function parallel in pyspark using an UDF?

Thanks

1 REPLY 1

Hubert-Dudek
Esteemed Contributor III

UDF functions are serialized and then executed on executors. I don't think it will be possible with Selenium.

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!