Ich habe eine MVC -Anwendung in C# geschrieben und auf IIS gehostet. In meinem C# Code versuche ich, ein Python -Skript aufzurufen, um auf die Scopus -Website zuzugreifen und Benutzerinformationen abzurufen. Das Python -Skript funktioniert perfekt, wenn Sie aus der Befehlszeile ausgeführt werden, aber wenn ich es aus meinem C# -Codus nenne, wirft es einen Fehler aus. Ich bin mit einem Erlaubnisproblem konfrontiert, also erstelle ich manuell einige Ordner (PIP, Python ...) und gebe IIS/Benutzer die Erlaubnis.
Error in python script: Traceback (most recent call last):
File "C:\inetpub\site\scopus.py", line 15, in
verify_success(sb)
File "C:\inetpub\site\scopus.py", line 9, in verify_success
sb.assert_element('//span[contains(text(), "Author Search")]', timeout=30)
File "C:\Windows\system32\config\systemprofile\AppData\Roaming\Python\Python312\site-packages\seleniumbase\fixtures\base_case.py", line 9428, in assert_element
self.wait_for_element_visible(selector, by=by, timeout=timeout)
File "C:\Windows\system32\config\systemprofile\AppData\Roaming\Python\Python312\site-packages\seleniumbase\fixtures\base_case.py", line 8853, in wait_for_element_visible
return page_actions.wait_for_element_visible(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Windows\system32\config\systemprofile\AppData\Roaming\Python\Python312\site-packages\seleniumbase\fixtures\page_actions.py", line 496, in wait_for_element_visible
timeout_exception(NoSuchElementException, message)
File "C:\Windows\system32\config\systemprofile\AppData\Roaming\Python\Python312\site-packages\seleniumbase\fixtures\page_actions.py", line 254, in timeout_exception
raise exc(msg)
seleniumbase.common.exceptions.NoSuchElementException: Message:
Element {//span[contains(text(), "Author Search")]} was not present after 30 seconds!
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\inetpub\site\scopus.py", line 24, in
verify_success(sb)
File "C:\inetpub\site\scopus.py", line 9, in verify_success
sb.assert_element('//span[contains(text(), "Author Search")]', timeout=30)
File "C:\Windows\system32\config\systemprofile\AppData\Roaming\Python\Python312\site-packages\seleniumbase\fixtures\base_case.py", line 9428, in assert_element
self.wait_for_element_visible(selector, by=by, timeout=timeout)
File "C:\Windows\system32\config\systemprofile\AppData\Roaming\Python\Python312\site-packages\seleniumbase\fixtures\base_case.py", line 8853, in wait_for_element_visible
return page_actions.wait_for_element_visible(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Windows\system32\config\systemprofile\AppData\Roaming\Python\Python312\site-packages\seleniumbase\fixtures\page_actions.py", line 496, in wait_for_element_visible
timeout_exception(NoSuchElementException, message)
File "C:\Windows\system32\config\systemprofile\AppData\Roaming\Python\Python312\site-packages\seleniumbase\fixtures\page_actions.py", line 254, in timeout_exception
raise exc(msg)
seleniumbase.common.exceptions.NoSuchElementException: Message:
Element {//span[contains(text(), "Author Search")]} was not present after 30 seconds!
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\inetpub\site\scopus.py", line 26, in
raise Exception("Detected!")
Exception: Detected!
Ich habe eine MVC -Anwendung in C# geschrieben und auf IIS gehostet. In meinem C# Code versuche ich, ein Python -Skript aufzurufen, um auf die Scopus -Website zuzugreifen und Benutzerinformationen abzurufen. Das Python -Skript funktioniert perfekt, wenn Sie aus der Befehlszeile ausgeführt werden, aber wenn ich es aus meinem C# -Codus nenne, wirft es einen Fehler aus. Ich bin mit einem Erlaubnisproblem konfrontiert, also erstelle ich manuell einige Ordner (PIP, Python ...) und gebe IIS/Benutzer die Erlaubnis. [code]Error in python script: Traceback (most recent call last): File "C:\inetpub\site\scopus.py", line 15, in verify_success(sb) File "C:\inetpub\site\scopus.py", line 9, in verify_success sb.assert_element('//span[contains(text(), "Author Search")]', timeout=30) File "C:\Windows\system32\config\systemprofile\AppData\Roaming\Python\Python312\site-packages\seleniumbase\fixtures\base_case.py", line 9428, in assert_element self.wait_for_element_visible(selector, by=by, timeout=timeout) File "C:\Windows\system32\config\systemprofile\AppData\Roaming\Python\Python312\site-packages\seleniumbase\fixtures\base_case.py", line 8853, in wait_for_element_visible return page_actions.wait_for_element_visible( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Windows\system32\config\systemprofile\AppData\Roaming\Python\Python312\site-packages\seleniumbase\fixtures\page_actions.py", line 496, in wait_for_element_visible timeout_exception(NoSuchElementException, message) File "C:\Windows\system32\config\systemprofile\AppData\Roaming\Python\Python312\site-packages\seleniumbase\fixtures\page_actions.py", line 254, in timeout_exception raise exc(msg) seleniumbase.common.exceptions.NoSuchElementException: Message: Element {//span[contains(text(), "Author Search")]} was not present after 30 seconds!
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\inetpub\site\scopus.py", line 24, in verify_success(sb) File "C:\inetpub\site\scopus.py", line 9, in verify_success sb.assert_element('//span[contains(text(), "Author Search")]', timeout=30) File "C:\Windows\system32\config\systemprofile\AppData\Roaming\Python\Python312\site-packages\seleniumbase\fixtures\base_case.py", line 9428, in assert_element self.wait_for_element_visible(selector, by=by, timeout=timeout) File "C:\Windows\system32\config\systemprofile\AppData\Roaming\Python\Python312\site-packages\seleniumbase\fixtures\base_case.py", line 8853, in wait_for_element_visible return page_actions.wait_for_element_visible( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Windows\system32\config\systemprofile\AppData\Roaming\Python\Python312\site-packages\seleniumbase\fixtures\page_actions.py", line 496, in wait_for_element_visible timeout_exception(NoSuchElementException, message) File "C:\Windows\system32\config\systemprofile\AppData\Roaming\Python\Python312\site-packages\seleniumbase\fixtures\page_actions.py", line 254, in timeout_exception raise exc(msg) seleniumbase.common.exceptions.NoSuchElementException: Message: Element {//span[contains(text(), "Author Search")]} was not present after 30 seconds!
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\inetpub\site\scopus.py", line 26, in raise Exception("Detected!") Exception: Detected!
with SB(uc=True) as sb: sb.uc_open_with_reconnect(f"https://www.scopus.com/authid/detail.uri?authorId={userId}", 3) try: verify_success(sb) except Exception: if sb.is_element_visible('input[value*="Verify"]'): sb.uc_click('input[value*="Verify"]') else: sb.uc_gui_click_captcha() try: verify_success(sb) except Exception: raise Exception("Detected!") finally: page_source = sb.get_page_source() document = BeautifulSoup(page_source, 'html.parser') citations_node = document.select_one("div[data-testid='metrics-section-citations-count'] span[data-testid='unclickable-count']") documents_node = document.select_one("div[data-testid='metrics-section-document-count'] span[data-testid='unclickable-count']") hindex_node = document.select_one("div[data-testid='metrics-section-h-index'] span[data-testid='unclickable-count']") name_node = document.select_one("h1[data-testid='author-profile-name'] strong") institute_node = document.select_one("span[data-testid='authorInstitute']") scopus_information = { "CitationsNumber": int(citations_node.text.replace(",", "") if citations_node else "0"), "Documents": int(documents_node.text if documents_node else "0"), "HIndex": int(hindex_node.text if hindex_node else "0"), "Name": name_node.text.strip() if name_node else "", "Institute": institute_node.text.strip() if institute_node else "" } print(json.dumps(scopus_information, indent=4)) [/code] [b] C# Code: [/b] [code] public class ScopusInformation { public string? Name { get; set; } public int? CitationsNumber { get; set; } public int? Documents { get; set; } public int? HIndex { get; set; } public string? Institute { get; set; } public string? ScopusId { get; set; } } public interface IScopusService { Task GetArticlesForUser(string userId); } public class ScopusServiceUsingPython(ILogger logger) : IScopusService { public async Task GetArticlesForUser(string userId) { string cmd = "py"; var result2 = await DoCmdAsync(cmd, $"scopus.py {userId}"); ScopusInformation? r2 = JsonSerializer.Deserialize(result2); return r2; } private async Task DoCmdAsync(string cmd, string args) { logger.LogWarning("DoCmd in python script {cmd} {args}", cmd, args); try { // First, ensure required modules are installed await EnsurePythonModulesAsync(cmd, new[] { "seleniumbase", "beautifulsoup4", "pyautogui" });
var start = new ProcessStartInfo { FileName = cmd, // cmd is full path to python.exe Arguments = args, // args is path to .py file and any cmd line args UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true };
using var process = new Process { StartInfo = start }; process.Start();
var outputTask = process.StandardOutput.ReadToEndAsync(); var errorTask = process.StandardError.ReadToEndAsync();
await Task.WhenAll(outputTask, errorTask);
string result = await outputTask; string error = await errorTask;
if (!process.WaitForExit(30000)) // 30 seconds timeout { process.Kill(); throw new TimeoutException("Python script execution timed out after 30 seconds."); }
if (!string.IsNullOrEmpty(error)) { logger.LogWarning("Error in python script: {error}", error); }
using var checkProcess = new Process { StartInfo = checkStart }; checkProcess.Start(); if (!checkProcess.WaitForExit(10000)) // 10 seconds timeout { checkProcess.Kill(); throw new TimeoutException($"Checking for Python module {module} timed out."); }
Ich habe eine MVC -Anwendung in C# geschrieben und auf IIS gehostet. In meinem C# Code versuche ich, ein Python -Skript aufzurufen, um auf die Scopus -Website zuzugreifen und Benutzerinformationen...
Hintergrund:
Ich habe ein Problem in vs Code, bei dem mein Python -Skript mit dem Taste run gut ausgeführt wird, aber stillschweigend fehlschlägt, wenn Debugg . /> Python 3.10
gegen Code mit...
Wir erstellen ein Docker -Bild für ein Java + Maven -Projekt, das eine Spring -Boot -Anwendung mit Kafka ausführt. 'Somename' in URL definiert :
Unzufriedene Abhängigkeit, die über den...
Ich habe ein Python-Skript geschrieben, das auf Bibliotheken basiert, die ich selbst erstellt habe. Ich habe in den jeweiligen Verzeichnissen eine __init__.py-Datei erstellt, um sie als...
Ich habe den folgenden Code, der in Zeile 27 fehlerhaft wird. Ich brauche keine Zeile 27 ( foto = imagetk.photoimage (IMG) ). Das Programm funktioniert jedoch auch nach dem Auftreten des Fehlers wie...