0

I need to write a python script to do some validation on GSH number, the page is here: https://www.businessregistration-inscriptionentreprise.gc.ca/ebci/brom/registry/registryPrompt.do

As you can see there are three parameters to be provided. My script is as below (thanks to enter link description here):

import urllib
import urllib2

url = 'https://www.businessregistration-inscriptionentreprise.gc.ca/ebci/brom/registry/registryPromptSubmit.do'
values = {'businessNumber' : 'Michael Foord',
      'businessName' : 'Northampton',
      'requestDate' : '2016-10-23' }

data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = response.read()
print the_page

I inspect the result and it shows the response ends with something like these: , here is a screenshot: enter image description here

What happened to the response? where is the mainContentOfPage indicated in the right after the section?

Thank you very much.

Community
  • 1
  • 1
PasLeChoix
  • 311
  • 1
  • 5
  • 21
  • your link shows me "404 File not found" – furas Oct 25 '16 at 00:01
  • Maybe it is because the page asked user to click on something to confirm, here is the previous page: [link](http://www.cra-arc.gc.ca/esrvc-srvce/tx/bsnss/gsthstrgstry/trms-eng.html), thank you for your finding, this maybe the cause. – PasLeChoix Oct 25 '16 at 00:05
  • probably this page use JavaScript/AJAX to add elements on page. `urllib`/`urllib2`/`requests` doesn't run scripts. – furas Oct 25 '16 at 00:05
  • I also checked the text between the
    and , they are as following: 0d 0a 20 20 20 20 0d 0a 0d 0a 0d 0a 09 09 0d 0a 0d 0a 0d 0a 0d 0a 0d 0a
    – PasLeChoix Oct 25 '16 at 00:06
  • `0d 0a` is hex code of enter - new line, `20` is hex code of space. – furas Oct 25 '16 at 00:07
  • Can you tell how to mock the button click in the previous page? I guess I need to run that first in the python script – PasLeChoix Oct 25 '16 at 00:08
  • the reason I check the hex code is to ensure there is no EOF kind of code – PasLeChoix Oct 25 '16 at 00:09
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/126560/discussion-between-paslechoix-and-furas). – PasLeChoix Oct 25 '16 at 00:10
  • use DevTools in Chrome/Firefox to see data send from browser to server. "I agree" button sends "POST" with "iagree=yes" – furas Oct 25 '16 at 00:13
  • maybe this button save info as cookies - it is easier to work with cookies (and session) using `requests` module. BTW. form on your page sends `action=Search` so server may check it too. – furas Oct 25 '16 at 00:17
  • can we move to the chatting room? [link](http://chat.stackoverflow.com/rooms/126560/discussion-between-paslechoix-and-furas), thanks. – PasLeChoix Oct 25 '16 at 00:17

0 Answers0