簡體   English   中英

無法使用 Selenium 打開新標簽

[英]Unable to open new tab with Selenium

我正在嘗試從 eBay 打開每個列表以進行抓取。 我的目標是在“for 循環”中打開每個 eBay 的列表,以便我可以抓取每個列表的數據。

不幸的是,我收到一條錯誤消息:

selenium.common.exceptions.JavascriptException:消息:javascript 錯誤:未定義鏈接

我的代碼:

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.

完整代碼: https://pastebin.com/pFdKU45d

太感謝了。 嚴重地。

引用是錯誤的:

driver.execute_script("window.open(\"" + link['href'] + "\")")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM