ich this_link gefolgt und ich konnte eine Dummy-Python-Datei von meinem C# Code wie folgt laufen ...kann nicht Python-Skript in C# laufen, die scrapy Spinne läuft
public JsonResult FetchscrapyDataUrl(String website)
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"C:\ProgramData\Anaconda3\python.exe";
start.Arguments = @"C:\Users\PycharmProjects\scraping_web\scrape_info\main.py";
//this is path to .py file from scrapy project
start.CreateNoWindow = false; // We don't need new window
start.UseShellExecute = false; // Do not use OS shell
//start.RedirectStandardOutput = true;// Any output, generated by application will be redirected back
start.RedirectStandardError = true; // Any error in standard output will be redirected back (for example exceptions)
Console.WriteLine("Python Starting");
start.RedirectStandardOutput = true;
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string stderr = process.StandardError.ReadToEnd(); // Here are the exceptions from our Python script
string result = reader.ReadToEnd(); // Here is the result of StdOut(for example: print "test")
Console.Write(result);
}
}
}
Jetzt weiß ich, dass ich laufen kann scrapy Spinne aus einer einzigen Datei main.py
so ...
from scrapy import cmdline
cmdline.execute("scrapy crawl text".split())
wenn ich main.py Datei von cmd in Windows ausführen es funktioniert gut, aber es funktioniert nicht, wenn ich es von C# -Code NET Framework ausgeführt werden. Der Fehler ist ...
"Scrapy 1.4.0 - no active project\r\n\r\nUnknown command: crawl\r\n\r\nUse \"scrapy\" to see available commands\r\n"
Jede Idee, wie diese laufen ... Oder bin ich etwas Pfad in Windows Einstellung fehlt ??
Oder sollte ich meine Spinne von C# auf eine andere Weise laufen ??
Stattdessen funktioniert, verwenden scrapyd API Ihre Schaber zu laufen, https: // scrapyd. readthedocs.io/en/stable/ ... Sie müssen nur eine POST-Anfrage senden, um einen Scraper auszuführen, und ich glaube, wie Sie eine POST-Anfrage in C# senden (Ich bin kein C# -Programmierer, sonst hätte ich Ihnen gesagt) – Umair
Danke für die Antwort ... können Sie mir einen Überblick über die Post-Anfrage in jeder Sprache geben, mit der Sie sich wohl fühlen .... – amrit
Grundsätzlich ist dies ist der cURL Befehl, um eine Spinne zu starten, 'curl' Befehl' curl http: // localhost: 6800/schedule.json -d projekt = meinprojekt -d spinne = spider2 -d anyOtherExtraParam = "Wert hier" 'Sie können kopieren und einfügen diesen Befehl in diesem Tool https://curl.trillworks.com/ hier und Sie haben den konvertierten Code in Python/PHP – Umair