Reputation: 345
I am trying to open each listing from eBay to scrape. My objective is to open each eBay's listing in a "for loop" so I can scrape each listing's data.
Unfortunately, I get an error stating:
selenium.common.exceptions.JavascriptException: Message: javascript error: link is not defined
My code:
driver = webdriver.Chrome('/Users/kenny/Dropbox/Python/Web Scrapping/Others/chromedriver')
driver.get('https://www.ebay.com/sch/i.html?_from=R40&_nkw=watches&_sacat=0&_pgn=1')
soup = BeautifulSoup(driver.page_source, 'lxml')
driver.maximize_window()
for link in soup.find_all('a', href=True):
if 'itm' in link['href']:
print(link['href'])
driver.execute_script("window.open(link['href'])") # Unable to open new tab of each watch to scrape each listing.
Entire Code: https://pastebin.com/pFdKU45d
Thank you so much. Seriously.
Upvotes: 0
Views: 45
Reputation: 55012
The quoting is wrong:
driver.execute_script("window.open(\"" + link['href'] + "\")")
Upvotes: 1