如何将Python脚本嵌入C ++?

时间:2019-11-09 23:05:12

标签: c++ python-3.x embed

我将python网络爬虫脚本嵌入到C ++中。 C ++将用于网站URL和字段的输入,我可能会更改输出方法以使用C ++进行控制。我停留在构建它的C ++部分。

如何使用网络抓取脚本实现此目的?

`static int numargs = 0;

/* Return the number of arguments of the application command line */
static PyObject*
emb_numargs(PyObject *self, PyObject *args)
{
    if(!PyArg_ParseTuple(args, ":numargs"))
    return NULL;
    return PyLong_FromLong(numargs);
 }

 static PyMethodDef EmbMethods[] = {
     {"numargs", emb_numargs, METH_VARARGS,
      "Return the number of arguments received by the process."},
     {NULL, NULL, 0, NULL}
  };

  static PyModuleDef EmbModule = {
         PyModuleDef_HEAD_INIT, "emb", NULL, -1, EmbMethods,
         NULL, NULL, NULL, NULL
    }

 static PyObject*
 PyInit_emb(void)
 {
    return PyModule_Create(&EmbModule);
}

`

0 个答案:

没有答案