-
-
Save srsbiz/1cd71dbe79369dd1682ddb2b2275a8e2 to your computer and use it in GitHub Desktop.
| /** | |
| * Redistribution and use in source and binary forms, with or without | |
| * modification, are permitted provided that the following conditions are met: | |
| * | |
| * * Redistributions of source code must retain the above copyright | |
| * notice, this list of conditions and the following disclaimer. | |
| * * Redistributions in binary form must reproduce the above copyright | |
| * notice, this list of conditions and the following disclaimer in the | |
| * documentation and/or other materials provided with the distribution. | |
| * * Neither the name of the <organization> nor the | |
| * names of its contributors may be used to endorse or promote products | |
| * derived from this software without specific prior written permission. | |
| * | |
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY | |
| * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
| * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| */ | |
| "use strict"; | |
| /** | |
| * https://github.com/ariya/phantomjs/blob/master/examples/waitfor.js | |
| */ | |
| function waitFor(testFunction, readyFunction, timeOutMillis) { | |
| var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3000, | |
| start = new Date().getTime(), | |
| condition = false, | |
| interval = setInterval(function() { | |
| if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) { | |
| condition = (typeof(testFunction) === "string" ? eval(testFunction) : testFunction()); | |
| } else { | |
| if(!condition) { | |
| phantom.exit(1); | |
| } else { | |
| typeof(readyFunction) === "string" ? eval(readyFunction) : readyFunction(); | |
| clearInterval(interval); | |
| } | |
| } | |
| }, 250); | |
| }; | |
| var system = require('system'), | |
| args = system.args, | |
| nip, | |
| nieJest = "Podmiot o podanym identyfikatorze podatkowym NIP nie jest zarejestrowany jako podatnik VAT", | |
| page = require('webpage').create(); | |
| if (1 === args.length) { | |
| console.log('NIP is required'); | |
| phantom.exit(1); | |
| } else { | |
| nip = args[1]; | |
| } | |
| page.open('https://ppuslugi.mf.gov.pl/', function(status) { | |
| if (status !== "success") { | |
| console.log("Unable to access network"); | |
| phantom.exit(); | |
| } else { | |
| waitFor(function(){ | |
| return page.evaluate(function() { return $('#SidebarActions_WebUMn li').length > 0; }); | |
| }, function(){ | |
| page.evaluate(function() { | |
| FWDC.executeAction(1005, null, 'FLOW'); | |
| }); | |
| waitFor(function(){ | |
| return page.evaluate(function() { return $('#b-7').length > 0; }); | |
| }, function(){ | |
| page.evaluate(function(nip) { | |
| $('#b-7').val(nip); | |
| $('#b-8').trigger('click'); | |
| }, nip); | |
| waitFor(function(){ | |
| return page.evaluate(function() { return $('#container_b-3').is(':visible'); }); | |
| }, function() { | |
| var msg = page.evaluate(function() { return $.trim($('#container_b-3').text()); }), | |
| date = page.evaluate(function() { return $.trim($('#caption2_b-b').text().split(':')[1]).split('-').reverse().join('-'); }), | |
| response = { | |
| "nip": nip, | |
| "msg": msg, | |
| "date": date, | |
| "status": msg == nieJest ? false : true | |
| }; | |
| system.stdout.write(JSON.stringify(response)); | |
| phantom.exit(); | |
| }); | |
| }); | |
| }); | |
| } | |
| }); |
Też guglałem, ale najwidoczniej ministerstwo inwestuje tylko w API do blokowania stron hazardowych :( Powyższy skrypt powstał właśnie z powodu braku oficjalnych narzędzi. Podejrzewam, że komercyjne produkty działają na tej samej zasadzie.
Cześć,
Słuchaj zrobiłem w pythonie program do sprawdzania statusu VAT w VIES i chciałem dodać jeszcze właśnie żeby sprawdzało w ministerstwie ale za cholerę nie mogę tego połączyć, całość zamknąłem w php i js, pobieranie danych z pliku csv i zapisywanie do niego z powrotem zwróconych wartości czy zweryfikowane czy nie. Jest tu jakaś dobra duszyczka która mogłaby mi pomóc? I czy wiecie jaką funkcję trzeba dodać do kodu żeby uzyskać Identyfikator zapytania?
Jakby ktoś wpadł na to jak ominąć formularz na https://ppuslugi.mf.gov.pl/ to dajcie znać. Jaja z JPK i aktywnymi NIPami się zaczynają, mogliby jakieś API wystawić.
edit:
Centrum Kompetencyjne Usług Elektronicznych uprzejmie informuje, że Ministerstwo Finansów pracuje nad udostępnieniem API do usługi "Wyszukiwania statusu podmiotu w VAT".
Jednak coś kombinują.
ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;
var options = new ChromeOptions();
if (czy_ukrycie)
{
options.AddArgument("--window-position=-32000,-32000");
options.AddArgument("headless");
// options.AddArguments("--disable-extensions");
}
//options.AddArgument("-incognito");
options.AddArgument("--disable-popup-blocking");
options.AddUserProfilePreference("disable-popup-blocking", "true");
//
var driver = new ChromeDriver(service, options);
try
{
driver.Navigate().GoToUrl(strona_mf); // "http://www.finanse.mf.gov.pl/web/wp/pp/sprawdzanie-statusu-podmiotu-w-vat");
driver.Manage().Window.Maximize();
Thread.Sleep(2000);
}
catch (Exception eee)
{
}
private int Sprawdz_chrome_seria(string nip, ChromeDriverService service, ChromeDriver driver, List<Sprawdz_NIP> sprawdz_nip, int i)
{
IWebElement element_b_7 = null;
int ilosc_petli = 200;
int czas_oczekiwania = 200;
//
// wpisanie nip
//
for (int z = 0; z < ilosc_petli; z++)
{
try
{
element_b_7 = driver.FindElementById("b-7");
element_b_7.SendKeys(nip);
break;
}
catch (Exception eee)
{
Thread.Sleep(czas_oczekiwania);
if (z == ilosc_petli - 1)
return -2;
}
}
//
// klawisz potwierdzenia nip
//
for (int z = 0; z < ilosc_petli; z++)
{
try
{
var element_b_8 = driver.FindElementById("b-8");
element_b_8.SendKeys(OpenQA.Selenium.Keys.Enter);
break;
}
catch (Exception eee)
{
Thread.Sleep(czas_oczekiwania);
if (z == ilosc_petli - 1)
return -2;
}
}
//
// odpowiedż z MF
//
string message = "";
for (int z = 0; z < ilosc_petli; z++)
{
try
{
var element_message = driver.FindElement(By.Id("container_b-3"));
message = element_message.Text;
if (message.Trim().Length > 10)
break;
}
catch (Exception eee)
{
Thread.Sleep(czas_oczekiwania);
if (z == ilosc_petli - 1)
return -2;
}
}
//
// czy pojawia się button wyczyść
//
IWebElement element_button;
for (int z = 0; z < ilosc_petli; z++)
{
try
{
element_button = driver.FindElement(By.Id("b-9"));
break;
}
catch (Exception eee)
{
Thread.Sleep(czas_oczekiwania);
if (z == ilosc_petli - 1)
return -2;
}
}
//
// element data
//
IWebElement element_data = null;
string data = null;
//
for (int z = 0; z < ilosc_petli; z++)
{
try
{
element_data = driver.FindElement(By.Id("caption2_b-b"));
data = (element_data.Text.Split(':')[1]).Trim();
data = data.Substring(6, 4) + "." + data.Substring(3, 2) + "." + data.Substring(0, 2);
break;
}
catch (Exception eee)
{
Thread.Sleep(czas_oczekiwania);
if (z == ilosc_petli - 1)
return -2;
}
}
bool czy_czynny = false;
if (message.IndexOf("NIP jest zarejestrowany") > -1)
{
czy_czynny = true;
}
NIP_mf = nip;
Opis_mf = message;
Czy_aktywny = czy_czynny;
Data_mf = data;
Czy_odczytano = true;
element_button = driver.FindElement(By.Id("b-9"));
element_button.Click();
Thread.Sleep(500);
return 1;
}
1 0x1befef7 bin/phantomjs() [0x1befef7] 2 0x19fa215 bin/phantomjs() [0x19fa215] 3 0x1b11757 bin/phantomjs() [0x1b11757] 4 0x7df3c2 bin/phantomjs() [0x7df3c2] 5 0x7df6d7 bin/phantomjs() [0x7df6d7] 6 0x7d951d bin/phantomjs() [0x7d951d] 7 0x7bcbdf bin/phantomjs() [0x7bcbdf] 8 0x48e471 bin/phantomjs() [0x48e471] 9 0x43c7e0 bin/phantomjs() [0x43c7e0] 10 0x48625f bin/phantomjs() [0x48625f] 11 0x22cc0bc bin/phantomjs() [0x22cc0bc] 12 0x919f8b bin/phantomjs() [0x919f8b] 13 0x7deec4 bin/phantomjs() [0x7deec4] 14 0x7df68b bin/phantomjs() [0x7df68b] 15 0x7df6d7 bin/phantomjs() [0x7df6d7] 16 0x7d951d bin/phantomjs() [0x7d951d] 17 0x7bcbdf bin/phantomjs() [0x7bcbdf] 18 0x48e471 bin/phantomjs() [0x48e471] 19 0x44d9fd bin/phantomjs() [0x44d9fd] 20 0x432c66 bin/phantomjs() [0x432c66] 21 0x42d19e bin/phantomjs() [0x42d19e] 22 0x7fb4ce1fd830 /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7fb4ce1fd830] 23 0x42ee89 bin/phantomjs() [0x42ee89] PhantomJS has crashed. Please read the bug reporting guide at <http://phantomjs.org/bug-reporting.html> and file a bug report.
Ja otrzymuję tylko taki wynik, co mogę robić źle?
Dobra robota! :) A czy ministerstwo udostępnia jakieś api tej usługi, webserwis lub coś w ten deseń aby zautomatyzować odpytywanie o nipy, ale nie wykorzystywac do tego "ukrytego" strzelania do ich strony? Guglałem, ale w wynikach znalazłem tylko płatne nip24.