You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jupyter中使用非Anaconda模块new-crawler遇语法错误求助

Fixing the SyntaxError with new-crawler in Jupyter

Hey there, let's break down why you're hitting that SyntaxError and fix it step by step:

1. First, fix the module import

Your line %aimport news-crawler as nc has a critical issue:

  • Python doesn't allow hyphens (-) in module names. Even though you installed the package as new-crawler, when importing it in Python, you need to use underscores (_) instead. So the correct import line is:
    import news_crawler as nc
    
  • Also, %aimport is Jupyter's auto-reload magic command—you only need that if you're actively editing the module and want changes to load automatically. For a standard first import, plain import works just fine.

2. You're mixing command-line syntax with Python code

The line nc reports USA -o out.csv -s 20160101 -e 20161231 -keyword election is how you'd run the tool in a terminal, not in a Python script/Jupyter cell. In Python, you need to call the actual function from the module and pass arguments using Python's syntax.

Assuming the news_crawler module has a reports function (which makes sense given your command), you'll need to pass parameters as keyword arguments like this:

nc.reports(
    country="USA",
    output="out.csv",
    start_date="20160101",
    end_date="20161231",
    keyword="election"
)

If you're not sure about the exact parameter names, you can quickly check the function's documentation with:

help(nc.reports)

Or list all available functions in the module to confirm:

dir(nc)

Alternative: Run it as a command-line command in Jupyter

If you prefer using the terminal-style syntax, you can prefix the command with ! to run it directly in a Jupyter cell (this works as long as your Anaconda environment is properly set up):

!news-crawler reports USA -o out.csv -s 20160101 -e 20161231 -keyword election

Either approach should get rid of that SyntaxError and let you run your crawler successfully.

内容的提问来源于stack exchange,提问作者user1150393

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:55:53