【问题标题】:Unable to open new tab with Selenium无法使用 Selenium 打开新标签
【发布时间】:2019-10-21 00:54:11
【问题描述】:

我正在尝试从 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

非常感谢。严重地。

【问题讨论】:

标签: python selenium


【解决方案1】:

引用错误:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-29
    • 2021-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多