Dear All,
Do we have any workflows to validate the VAT ID pertains to UK using below website.
https://www.tax.service.gov.uk/check-vat-number/known
as this was previously used to validate the status of VAT ID in VIES web portal.
Regards
Mahadeva Swamy
An API based approach is always preferable, but I was able to leverage Alteryx + Python + Selenium to remote control my web browser, load the value, hit enter, and scrape the resulting page. I took my inspiration from this page: https://community.alteryx.com/t5/Alteryx-Designer-Discussions/Python-Code-Tool-Web-Scraping-Dynamic-Websites-Using-Selenium/td-p/300335
Here is my Python script that I used for the process:
# Import necessary requirements and install if does not existfrom ayx import PackagePackage.installPackages(['pandas','numpy','selenium', 'urllib3'])from ayx import Alteryxfrom selenium import webdriverfrom selenium.webdriver.common.keys import Keysimport timefrom time import sleepimport pandas
#Read in VAT NumberVATdf = Alteryx.read("#1")VAT = str(VATdf.iloc[0, 0])
# Start the WebDriver and load the pagewd = webdriver.Chrome("C:/Program Files/Alteryx/bin/Plugins/chromedriver")wd.get("https://www.tax.service.gov.uk/check-vat-number/enter-vat-details")
# VAT variable to be sent in to target element#VAT = "GB243510593"
#Identify target element, send VAT, and hit returnelem = wd.find_element_by_id("target")elem.send_keys(VAT)elem.send_keys(Keys.RETURN)
# let page load for a few seconds before scrapingtime.sleep(5)
# And grab the page whole HTML sourcehtml_page = wd.page_source
# Attempt to close chromium instancewd.quit()
# Turn the variabe with html page into Pandas' DFdf = pandas.DataFrame({"html_page":[html_page]})
# Write the data frame to Alteryx workflow for downstream processingAlteryx.write(df,1)
You can either turn this workflow into a macro where you add a control parameter and action tool to the text input and a macro output at the end, or you could modify the python scrip to loop through every value to output a row to then be parsed. Hopefully this is a helpful start! I have attached my workflow to this post.
Dear @BrandonB ,
thanks for the time and effort on this.
However, when I check in my C drive I did not fine "chromedriver", can you please advise where do I download the same in order to run the scrip given in the workflow.
just dropping in to say that's an awesome solution @BrandonB . Big fan of the python tool being used in workflows, and Selenium is definitely the next thing for me to learn on that avenue!
Also, Yeah it may require pointing at the chromedriver specifically in the code, i've had a similar issue in the past.cheers!TheOC