3

Im trying to submit form on page http://pretraga2.apr.gov.rs/ObjedinjenePretrage/Search/Search

However im receving error (HTML) like:

<!DOCTYPE html>
<html><head>
    <title>Error</title>
</head>
<body>
    <h2>
        Sorry, an error occurred while processing your request.
    </h2>

</body></html>

Current Python script:

#!/usr/bin/python
# vim: set fileencoding=utf-8 :
import win_unicode_console

win_unicode_console.enable()

import requests
from bs4 import BeautifulSoup

import urllib.parse
import re
from robobrowser import RoboBrowser

# import warnings
# warnings.filterwarnings("ignore")

# Browse to Genius
browser = RoboBrowser(history=True)
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
       'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
       'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
       'Accept-Encoding': 'none',
       'Accept-Language': 'en-US,en;q=0.8',
       'Connection': 'keep-alive'}
s = requests.Session()
s.headers = hdr
browser = RoboBrowser(session=s)
browser.open('http://pretraga2.apr.gov.rs/ObjedinjenePretrage/Search/Search')
#
form = browser.get_form(action='/ObjedinjenePretrage/Search/SearchResult')
form['SearchByRegistryCodeString'].value = '53254136'
browser.submit_form(form)

print(browser.parsed)

I have tried to add headers, but no luck. What else can be the problem?

RhymeGuy
  • 2,102
  • 5
  • 32
  • 62

1 Answers1

1

This has been solved by now. I have noticed that there are two forms on page with identical names. I think that the first one (which was hidden by display:none) was submitted as honeypot.

Anyway the solutions is:

form = browser.get_forma(action='/ObjedinjenePretrage/Search/SearchResult')[1]
RhymeGuy
  • 2,102
  • 5
  • 32
  • 62