I want to call these functions from a separate Python file.
I want to specify the URL in run.py and run the functions from download.py in run.py...
But I keep getting this error below
Traceback (most recent call last):
File "app.py", line 7, in <module>
getTumblrPage()
File "/Users/matt/Python/Instagram Bots/testing/download.py", line 20, in getTumblrPage
driver.get(url)
NameError: name 'driver' is not defined
I've tried putting the variables in both files, or just one. Either way, not sure what to do.
Below is download.py
from selenium import webdriver
from bs4 import BeautifulSoup
from time import sleep
import urllib.request
import pandas as pd
import requests
import urllib
import base64
import csv
import time
def getTumblrPage():
driver.get(url)
# If page is infinity scroll, use this method to scrape more photos
def pageScroll():
driver.maximize_window()
driver.execute_script("window.scrollBy(0,document.body.scrollHeight)")
print ('Page scroll 1/5')
sleep(2)
driver.execute_script("window.scrollBy(0,document.body.scrollHeight)")
print ('Page scroll 2/5')
sleep(2)
driver.execute_script("window.scrollBy(0,document.body.scrollHeight)")
print ('Page scroll 3/5')
sleep(2)
driver.execute_script("window.scrollBy(0,document.body.scrollHeight)")
print ('Page scroll 4/5')
sleep(2)
driver.execute_script("window.scrollBy(0,document.body.scrollHeight)")
print ('Page scroll 5/5')
sleep(2)
Below is run.py
from download import *
url = "https://vjeranski.tumblr.com/"
driver = webdriver.Chrome(executable_path="/Users/matt/Python/chromedriver")
getTumblrPage()
pageScroll()
driver, that isn't defined. Python global variables aren't global across the entire process, they are module global.