WEBBrowser i javascript downlad file

0

Witam

Mam problem z pobraniem pliku ze strony.
Tworzę aplikacje do automatycznego logowani i pobierania dokumentów.
Logowanie ogarnąłem ale mam problem z pobraniem pliku.
Mianowicie nie ma do końca urla do pliku jest tylko javascript

<a id="ctl00_Form_btnDownload" style="margin-right: 30px;" onclick="ForcePostback();" href="javascript:__doPostBack('ctl00$Form$btnDownload','')">Pobierz dokument</a>

nawet po kliknięciu wyskakuje tylko dialog box do niego tez nie wiem jak się dobrać aby kliknąć

Pozdrawiam
Daniel

0

włącz sniffer, rozpocznij pobieranie plikuw 'normalniej' przeglądarce, sprawdź jak wygląda url, utwórz w kodzie url do pobierania na podstawie analizy tego ze sniffera

0

No tak tylko że chyba sniffery nie widzą https?

0

Sniffer podaj mi tylko obecnego urla gdyż iż ponieważ pod przyciskiem jest postback strona zostaje przeładowana z wywołaniem funkcji javascript który od razu wyświetla okienko do pobierania dokumentu.

0

Zacząłem inaczej bo sniffer nic przydatnego nie dopowiadał tylko ten sam url.

Mam z tym problem nigdy wcześnie tego nie robiłem i nie do końca działa mianowicie nie znajduje mi przycisku "Zapisz"

public class Win32API
{
public enum WindowState : int
{
SW_NORMAL = 1,
SW_MAXIMIZE = 3,
SW_MINIMIZE = 6,
SW_RESTORE = 9
}

[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr intPtWnd, int intCmdShow);

[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll")]
public static extern bool SetActiveWindow(IntPtr hWnd);

[DllImport("user32.dll")]
public static extern IntPtr GetLastActivePopup(IntPtr intPtWnd);

[DllImport("user32.dll")]
public static extern bool IsWindowEnabled(IntPtr intPtWnd);

[DllImport("user32.dll")]
public static extern bool IsIconic(IntPtr intPtWnd);

[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
}
...

using (Process current = Process.GetCurrentProcess())
{
foreach (Process proc in Process.GetProcessesByName(current.ProcessName))
{
// Get the process, that is not the current one (the previous instance) 
if (proc.Id == current.Id)
{
IntPtr ptrWnd = proc.MainWindowHandle;

// Get handle to popup (child) window, if there is any 
IntPtr ptrPopupWnd = Win32API.GetLastActivePopup(ptrWnd);

// If child window is found, it is the one to be brought to foreground 
if (ptrPopupWnd != null && Win32API.IsWindowEnabled(ptrPopupWnd))
{
IntPtr btnHandlr = Win32API.FindWindowEx((IntPtr)ptrPopupWnd, IntPtr.Zero, "Button", "Zapisz");

Win32API.SetActiveWindow(ptrPopupWnd);
//Win32API.SetForegroundWindow(ptrPopupWnd);
const int BM_CLICK = 0x00F5;
Win32API.SendMessage(btnHandlr, BM_CLICK, new IntPtr(0), new IntPtr(0));

//Domyślnie kursor jest na Anulu więc próbowałem nacisnąć klawisz w left i enter aby zapisać ale komputer w tym momencie się zawiesza
//SendKeys.Send("{LEFT}");
//SendKeys.Send("{ENTER}");

}
}
}
}

0

jak możesz pokaż adres strony, z której chcesz pobrać plik

0

Nie mogę bo to strona/ aplikacja tylko do faktury elektronicznych.
Ale wszystkie przyciski działają na kodzie javascript url się nie zmienia.

0

Zmieniłem podejście i użyłem Selenium ale mam problem pomimo wpisaniu mime type nadal wyskakuje okno do zapisu/podglądu
FirefoxProfile profile = new FirefoxProfile();
String pathe = "C:\Ktemp";
profile.SetPreference("browser.download.folderList", 2);
profile.SetPreference("browser.download.dir", pathe);
profile.SetPreference("browser.download.manager.alertOnEXEOpen", false);
profile.SetPreference("browser.helperApps.alwaysAsk.force", false);
profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.fdf,application/vnd.adobe.xfdf,application/pdf,application/x-pdf,application/acrobat,application/vnd.pdf,text/pdf,text/x-pdf,application/x-bzpdf,application/x-gzpdf,application/x-msexcel,application/excel,application/x-excel,application/excel,application/x-excel,application/excel,application/vnd.ms-excel,application/x-excel,application/x-msexcel");

0

Działa i tylko w takiej konfiguracji.

FirefoxProfile profile = new FirefoxProfile();
                    String pathe = "C:\\Ksiegowosctemp";
                    profile.SetPreference("browser.download.folderList", 2);
                    profile.SetPreference("browser.download.dir", pathe);
                    profile.SetPreference("browser.download.manager.alertOnEXEOpen", false);
                    profile.SetPreference("browser.helperApps.alwaysAsk.force", false);
                    profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream");//,application/vnd.fdf,application/vnd.adobe.xfdf,application/pdf,application/x-pdf,application/acrobat,application/vnd.pdf,text/pdf,text/x-pdf,application/x-bzpdf,application/x-gzpdf,application/x-msexcel,application/excel,application/x-excel,application/excel,application/x-excel,application/excel,application/vnd.ms-excel,application/x-excel,application/x-msexcel");


                    profile.SetPreference("browser.download.folderList", 2);
                    profile.SetPreference("browser.download.dir", pathe);
                    profile.SetPreference("browser.download.manager.alertOnEXEOpen", false);
                    profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/msword, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream");
                    //profile.SetPreference("browser.download.manager.showWhenStarting", false);
                    profile.SetPreference("browser.download.manager.focusWhenStarting", false);
                    profile.SetPreference("browser.download.useDownloadDir", true);
                    profile.SetPreference("browser.helperApps.alwaysAsk.force", false);
                    profile.SetPreference("browser.download.manager.alertOnEXEOpen", false);
                    profile.SetPreference("browser.download.manager.closeWhenDone", true);
                    profile.SetPreference("browser.download.manager.showAlertOnComplete", false);
                    profile.SetPreference("browser.download.manager.useWindow", false);
                    profile.SetPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
                    profile.SetPreference("pdfjs.disabled", true); 

1 użytkowników online, w tym zalogowanych: 0, gości: 1