{"id":90,"date":"2014-03-21T15:39:00","date_gmt":"2014-03-21T12:39:00","guid":{"rendered":"http:\/\/blog.successionua.com\/?p=90"},"modified":"2014-03-21T15:39:00","modified_gmt":"2014-03-21T12:39:00","slug":"%d0%b8%d1%81%d0%bf%d0%be%d0%bb%d1%8c%d0%b7%d0%be%d0%b2%d0%b0%d0%bd%d0%b8%d0%b5-%d0%b1%d0%b8%d0%b1%d0%bb%d0%b8%d0%be%d1%82%d0%b5%d0%ba%d0%b8-mechanize-%d0%b2-python-%d0%b4%d0%bb%d1%8f-%d0%b0%d0%b2","status":"publish","type":"post","link":"https:\/\/geckich.space\/?p=90","title":{"rendered":"\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Mechanize \u0432 Python \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0432\u0435\u0431-\u0444\u043e\u0440\u043c \u0438 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u043e\u0432"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\u0414\u043b\u044f \u044f\u0437\u044b\u043a\u0430 Python \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0432\u0435\u0431-\u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438. \u042d\u0442\u043e \u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f urllib \/ urllib2 \u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 &#8211; <a href=\"http:\/\/wwwsearch.sourceforge.net\/mechanize\/\" target=\"_blank\" rel=\"noopener noreferrer\">mechanize<\/a>, Twill, Request, Client Form.<\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 mechanize, \u0442. \u043a. \u0438\u043c\u0435\u043d\u043d\u043e \u0435\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u043c\u043d\u0435 &#8220;\u043f\u043e\u0431\u0435\u0434\u0438\u0442\u044c&#8221; \u0437\u0430\u0434\u0430\u0447\u0443 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u0432\u0435\u0431-\u0441\u0430\u0439\u0442\u0430.<\/p>\n<p>\u0421\u0443\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u044f \u0431\u0443\u0434\u0443 \u0438\u0437\u043b\u0430\u0433\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u043d\u043e, \u0442. \u043a. \u043d\u0435 \u043c\u043e\u0433\u0443 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u0437\u0434\u0435\u0441\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u043e \u043d\u0430\u0434\u0435\u044e\u0441\u044c &#8211; \u0432\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e.<\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u0430\u0441\u044c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u0430\u0445:<\/p>\n<ul style=\"text-align: left;\">\n<li>\u0434\u043b\u044f \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0430\u0439\u0442\u0435. \u041f\u0440\u0438\u0447\u0435\u043c, \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e forms, \u0430 \u043d\u0435 Basic HTTP.&nbsp;<\/li>\n<li>\u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u044b\u043b\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u0443\u043a\u0438\u0441\u044b, \u0434\u0430\u0431\u044b \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0435 \u043f\u0440\u043e\u043f\u0430\u043b\u0430.&nbsp;<\/li>\n<li>\u043f\u0443\u0442\u0435\u043c \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439 \u0441\u043e \u0441\u043f\u0438\u0441\u043a\u0430\u043c\u0438 (SelectControl) \u0432\u044b\u0431\u0438\u0440\u0430\u043b\u0438\u0441\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f.&nbsp;<\/li>\n<li>\u0434\u0430\u043b\u0435\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d, \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0432\u0448\u0438\u0439 \u0441\u0430\u0447\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u0441\u0441\u044b\u043b\u043a\u0435 \u0431\u043e\u043b\u0435 1 \u0440\u0430\u0437\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b GET \u0437\u0430\u043f\u0440\u043e\u0441\u0430.&nbsp;<\/li>\n<li>\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u0438 \u0432\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0435\u0445\u043e\u0440\u043e\u0448\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043d\u0430 \u043e\u0434\u043d\u043e\u0439 html-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u0444\u043e\u0440\u043c\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043a\u043d\u043e\u043f\u043a\u0430\u043c\u0438 \u0442\u0438\u043f\u0430 Submit.<\/li>\n<\/ul>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0435\u043c\u0441. \u0412\u043d\u0430\u0447\u0430\u043b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a. Mechanize \u043d\u0435 \u0438\u0434\u0435\u0442 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u043f\u043e\u0441\u0442\u0430\u0432\u043a\u0435 \u0441 Python &nbsp;\u0438 \u0435\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0438\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0437\u044c\u044e PiPy \u0438\u043b\u0438 \u0432\u0440\u0443\u0447\u043d\u0443\u044e, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e <a href=\"http:\/\/wwwsearch.sourceforge.net\/mechanize\/download.html\" target=\"_blank\" rel=\"noopener noreferrer\">\u043d\u0430 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0430\u0439\u0442\u0435<\/a> (python setup.py install).<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #202020; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;\">\n<pre style=\"line-height: 125%; margin: 0;\"><span style=\"color: #6ab825; font-weight: bold;\">import<\/span> <span style=\"color: #447fcf; text-decoration: underline;\">cookielib<\/span><span style=\"color: #d0d0d0;\">,<\/span> <span style=\"color: #447fcf; text-decoration: underline;\">shutil<\/span><span style=\"color: #d0d0d0;\">,<\/span> <span style=\"color: #447fcf; text-decoration: underline;\">os<\/span><br \/><span style=\"color: #6ab825; font-weight: bold;\">from<\/span> <span style=\"color: #447fcf; text-decoration: underline;\">mechanize<\/span> <span style=\"color: #6ab825; font-weight: bold;\">import<\/span> <span style=\"color: #d0d0d0;\">Browser<\/span><br \/><\/pre>\n<\/div>\n<p>\u0414\u0430\u043b\u0435\u0435, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u044b: \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 Browser \u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u0443\u043a\u0438\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u044f\u0435\u043c \u043a \u043d\u0430\u0448\u0435\u043c\u0443 Browser. \u041e\u0431\u044a\u0435\u043a\u0442 Browser \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043f\u043e \u0441\u043c\u044b\u0441\u043b\u0443 \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u043d\u0430 \u0432\u043a\u043b\u0430\u0434\u043a\u0443 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0433\u043e \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430. \u0422. \u0435. \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044e \u043f\u043e web-\u0441\u0430\u0439\u0442\u0443, \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e, \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u0443\u043a\u0438\u0441\u044b \u0438 \u0442. \u0434.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #202020; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;\">\n<pre style=\"line-height: 125%; margin: 0;\"><span style=\"color: #d0d0d0;\">br<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #d0d0d0;\">Browser()<\/span><br \/><span style=\"color: #999999; font-style: italic;\"># Create cookie jar and attach it to Browser<\/span><br \/><span style=\"color: #d0d0d0;\">cj<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #d0d0d0;\">cookielib.LWPCookieJar()<\/span><br \/><span style=\"color: #d0d0d0;\">br.set_cookiejar(cj)<\/span><br \/><\/pre>\n<\/div>\n<p>\u0417\u0430\u0442\u0435\u043c, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c html \u0445\u044d\u0434\u044d\u0440\u044b \u0438 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c URL \u043d\u0443\u0436\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0438 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 Browser.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #202020; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;\">\n<pre style=\"line-height: 125%; margin: 0;\"><span style=\"color: #999999; font-style: italic;\"># Add some headers<\/span><br \/><span style=\"color: #d0d0d0;\">br.addheaders<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #d0d0d0;\">[(<\/span><span style=\"color: #ed9d13;\">'User-agent'<\/span><span style=\"color: #d0d0d0;\">,<\/span> <span style=\"color: #ed9d13;\">'Mozilla\/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko\/2008071615 Fedora\/3.0.1-1.fc9 Firefox\/3.0.1'<\/span><span style=\"color: #d0d0d0;\">)]<\/span><br \/><span style=\"color: #999999; font-style: italic;\"># Open url in Browser instance<\/span><br \/><span style=\"color: #d0d0d0;\">br.open(<\/span><span style=\"color: #ed9d13;\">'http:\/\/www.example.com\/download.aspx'<\/span><span style=\"color: #d0d0d0;\">)<\/span><br \/><\/pre>\n<\/div>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0444\u043e\u0440\u043c\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u043c \u0432\u043d\u043e\u0441\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435. nr=0 &#8211; \u0438\u043d\u0434\u0435\u043a\u0441 \u0444\u043e\u0440\u043c\u044b \u043f\u043e \u0441\u0447\u0435\u0442\u0443 \u0432 \u043a\u043e\u0434\u0435 \u0432\u0435\u0431-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b (0,1,2 &#8230;) \u0418 \u0432\u0432\u043e\u0434\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043f\u043e\u043b\u044f \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 (\u0434\u043b\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 TextControl):<\/p>\n<p><span style=\"color: #e69138;\"><b>br[&#8220;id_html_\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430&#8221;] = &#8220;\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435&#8221;<\/b><\/span><\/p>\n<p>id \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0434\u0432\u0443\u043c\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:<\/p>\n<ul style=\"text-align: left;\">\n<li>\u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 Google Chrome \u043d\u0430\u0436\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u043e\u0439 \u043a\u043d\u043e\u043f\u043a\u043e\u0439 \u043c\u044b\u0448\u0438 \u043d\u0430 \u043d\u0443\u0436\u043d\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 \u0438 \u0432\u044b\u0431\u0440\u0430\u0442\u044c <b>\u041f\u0440\u043e\u0441\u043c\u043e\u0442\u0440 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430<\/b>, \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u0430\u0432\u043e\u0439 \u043a\u043d\u043e\u043f\u043a\u043e\u0439 \u043d\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 \u0438 <b>Copy as HTML<\/b>. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e, \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0432 \u043b\u044e\u0431\u043e\u0439 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440.&nbsp;<\/li>\n<li>\u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u043a\u043e\u0434 \u0432 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0435 python \u0438\u043b\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u0435:<\/li>\n<\/ul>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #202020; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;\">\n<pre style=\"line-height: 125%; margin: 0;\"><span style=\"color: #6ab825; font-weight: bold;\">import<\/span> <span style=\"color: #447fcf; text-decoration: underline;\">cookielib<\/span><br \/><span style=\"color: #6ab825; font-weight: bold;\">from<\/span> <span style=\"color: #447fcf; text-decoration: underline;\">mechanize<\/span> <span style=\"color: #6ab825; font-weight: bold;\">import<\/span> <span style=\"color: #d0d0d0;\">ParseResponse,<\/span> <span style=\"color: #d0d0d0;\">urlopen<\/span><br \/><span style=\"color: #d0d0d0;\">response<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #d0d0d0;\">urlopen(<\/span><span style=\"color: #ed9d13;\">\"http:\/\/www.eoddata.com\/download.aspx\"<\/span><span style=\"color: #d0d0d0;\">)<\/span><br \/><span style=\"color: #d0d0d0;\">forms<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #d0d0d0;\">ParseResponse(response,<\/span> <span style=\"color: #d0d0d0;\">backwards_compat=<\/span><span style=\"color: #24\n909d;\">False<\/span><span style=\"color: #d0d0d0;\">)<\/span><br \/><span style=\"color: #d0d0d0;\">form<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #d0d0d0;\">forms[<\/span><span style=\"color: #3677a9;\">0<\/span><span style=\"color: #d0d0d0;\">]<\/span><br \/><span style=\"color: #6ab825; font-weight: bold;\">print<\/span> <span style=\"color: #d0d0d0;\">form<\/span><br \/><\/pre>\n<\/div>\n<p>\u0412\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0444\u043e\u0440\u043c\u044b \u0438 \u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435:<\/p>\n<p><b><span style=\"color: #e69138;\">&lt;\u0422\u0438\u043f(id=\u0441\u043f\u0438\u0441\u043e\u043a_\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439)&gt;<\/span><\/b><\/p>\n<p>\u0412\u0440\u043e\u0434\u0435 \u0442\u0430\u043a\u043e\u0433\u043e:<\/p>\n<p><span style=\"color: #e69138;\">&lt;aspnetForm POST http:\/\/www.example.com\/download.aspx application\/x-www-form-urlencoded<\/span><br \/><span style=\"color: #e69138;\">&nbsp; &lt;SelectControl(ctl00$DataFormat=[17, 2, 36, 16, 27, 28, 33, 32, 8, 24, 35, *9, 1, 39, 11, 14, 6, 5, 4, 12, 3, 26, 15])&gt;<\/span><br \/><span style=\"color: #e69138;\">&nbsp; &lt;SubmitControl(ctl00$Download=Download) (readonly)&gt;<\/span><br \/><span style=\"color: #e69138;\">&nbsp; &lt;TextControl(ctl00$txtEmail=)&gt;<\/span><br \/><span style=\"color: #e69138;\">&nbsp; &lt;PasswordControl(ctl00$txtPassword=)&gt;<\/span><br \/><span style=\"color: #e69138;\">&nbsp; &lt;CheckboxControl(ctl00$Remember=[on])&gt;<\/span><br \/><span style=\"color: #e69138;\">&nbsp; &lt;SubmitControl(ctl00$btnLogin=Login) (readonly)&gt;&gt;<\/span><\/p>\n<p>\u0418\u0442\u0430\u043a, \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #202020; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;\">\n<pre style=\"line-height: 125%; margin: 0;\"><span style=\"color: #999999; font-style: italic;\"># Select form for modification and \"enter\" login info<\/span><br \/><span style=\"color: #d0d0d0;\">br.select_form(nr=<\/span><span style=\"color: #3677a9;\">0<\/span><span style=\"color: #d0d0d0;\">)<\/span><br \/><span style=\"color: #d0d0d0;\">br[<\/span><span style=\"color: #ed9d13;\">\"ctl00$txtEmail\"<\/span><span style=\"color: #d0d0d0;\">]<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #ed9d13;\">\"User\"<\/span><br \/><span style=\"color: #d0d0d0;\">br[<\/span><span style=\"color: #ed9d13;\">\"ctl00$txtPassword\"<\/span><span style=\"color: #d0d0d0;\">]<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #ed9d13;\">\"Secret\"<\/span><br \/><span style=\"color: #999999; font-style: italic;\"># Submit form<\/span><br \/><span style=\"color: #d0d0d0;\">br.submit(nr=<\/span><span style=\"color: #3677a9;\">3<\/span><span style=\"color: #d0d0d0;\">)<\/span><br \/><\/pre>\n<\/div>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0443<\/p>\n<p><b><span style=\"color: #e69138;\">br.submit(nr=3)<\/span><\/b><\/p>\n<p>\u0412 \u0441\u043a\u043e\u0431\u043a\u0430\u0445 \u0443\u043a\u0430\u0437\u0430\u043d \u043d\u043e\u043c\u0435\u0440 \u043a\u043d\u043e\u043a\u0438 \u0442\u0438\u043f\u0430 Submit \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443 \u0435\u0451 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0432 html-\u043a\u043e\u0434\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b. \u042d\u0442\u043e \u0432\u0430\u0436\u043d\u043e, \u0435\u0441\u043b\u0438 \u0432 \u0444\u043e\u0440\u043c\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043d\u043e\u043f\u043e\u043a \u0442\u0438\u043f\u0430 Submit, \u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u043a\u0430\u043a \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435). \u041d\u0443\u043c\u0435\u0440\u0430\u0446\u0438\u044f 0,1,2&#8230;<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0441\u043f\u0438\u0441\u043a\u0430\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 (\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u044b\u0448\u0435 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438):<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #202020; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;\">\n<pre style=\"line-height: 125%; margin: 0;\"><span style=\"color: #d0d0d0;\">br.select_form(nr=<\/span><span style=\"color: #3677a9;\">0<\/span><span style=\"color: #d0d0d0;\">)<\/span><br \/><span style=\"color: #999999; font-style: italic;\"># Select Options<\/span><br \/><span style=\"color: #d0d0d0;\">br[<\/span><span style=\"color: #ed9d13;\">\"ctl00$cboSomething\"<\/span><span style=\"color: #d0d0d0;\">]<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #d0d0d0;\">[<\/span><span style=\"color: #ed9d13;\">\"EXAMPLE\"<\/span><span style=\"color: #d0d0d0;\">,]<\/span><br \/><span style=\"color: #d0d0d0;\">br[<\/span><span style=\"color: #ed9d13;\">\"ctl00$cboDataFormat\"<\/span><span style=\"color: #d0d0d0;\">]<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #d0d0d0;\">[<\/span><span style=\"color: #ed9d13;\">\"11\"<\/span><span style=\"color: #d0d0d0;\">,]<\/span><br \/><span style=\"color: #999999; font-style: italic;\"># Update page<\/span><br \/><span style=\"color: #d0d0d0;\">br.submit(nr=<\/span><span style=\"color: #3677a9;\">1<\/span><span style=\"color: #d0d0d0;\">)<\/span><br \/><\/pre>\n<\/div>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0440\u0441\u0438\u043c \u043a\u043e\u0434 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0444\u0430\u0439\u043b. \u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u0431\u0443\u0434\u0435\u0442, \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, \u0440\u0430\u0437\u043d\u044b\u043c &#8211; \u043f\u043e\u0442\u043e\u043c\u0443 \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u0435\u0433\u043e \u0437\u0434\u0435\u0441\u044c.<\/p>\n<p>\u0421\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b (\u0441\u0447\u0438\u0442\u0430\u044f, \u0447\u0442\u043e \u0438\u0441\u043a\u043e\u043c\u044b\u0439 URL \u043d\u0430 \u0444\u0430\u0439\u043b \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 download_url):<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #202020; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;\">\n<pre style=\"line-height: 125%; margin: 0;\"><span style=\"color: #d0d0d0;\">local_path<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #ed9d13;\">\"\/home\/user\"<\/span><br \/><span style=\"color: #d0d0d0;\">filename<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #ed9d13;\">\"very_important.txt\"<\/span><br \/><span style=\"color: #d0d0d0;\">f<\/span> <span style=\"color: #d0d0d0;\">=<\/span> <span style=\"color: #d0d0d0;\">br.retrieve(download_url)[<\/span><span style=\"color: #3677a9;\">0<\/span><span style=\"color: #d0d0d0;\">]<\/span><br \/><span style=\"color: #999999; font-style: italic;\"># Copy saved file to normal location<\/span><br \/><span style=\"color: #d0d0d0;\">shutil.copy2(f,os.path.join(local_path,<\/span> <span style=\"color: #d0d0d0;\">filename))<\/span><br \/><\/pre>\n<\/div>\n<p><\/p>\n<div>\u0412 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 f \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0443\u0442\u044c \u043a \u0441\u043a\u0430\u0447\u0430\u043d\u043d\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443, \u043e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0438\u043c\u044f \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \/tmp. \u0414\u0430\u043b\u0435\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u043d\u0443\u0436\u043d\u043e\u0435 \u043d\u0430\u043c \u043c\u0435\u0441\u0442\u043e.<\/p>\n<p>\u0421\u0441\u044b\u043b\u043a\u0438:<\/p>\n<ul style=\"text-align: left;\">\n<li>http:\/\/stockrt.github.io\/p\/emulating-a-browser-in-python-with-mechanize\/<\/li>\n<li>http:\/\/www.voidspace.org.uk\/python\/articles\/authentication.shtml<\/li>\n<li>http:\/\/mozgovipc.blogspot.com\/2012\/06\/python-http-basic-authentication-with.html<\/li>\n<li>http:\/\/docs.python-requests.org\/en\/latest\/<\/li>\n<li>http:\/\/stackoverflow.com\/questions\/9541677\/urllib2-post-request<\/li>\n<li>http:\/\/docs.python.org\/2\/howto\/urllib2.html<\/li>\n<li>http:\/\/stackoverflow.com\/questions\/9288662\/need-more-mechanize-documentation-python<\/li>\n<li>http:\/\/www.pythonforbeginners.com\/cheatsheet\/python-mechanize-cheat-sheet<\/li>\n<li>http:\/\/blog.spritecloud.com\/2010\/01\/posting-forms-with-python\/<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div>http:\/\/geckich.blogspot.com\/<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u0414\u043b\u044f \u044f\u0437\u044b\u043a\u0430 Python \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0432\u0435\u0431-\u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438. \u042d\u0442\u043e \u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f urllib \/ urllib2 \u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 &#8211; mechanize, Twill, Request, Client Form. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 mechanize, \u0442. \u043a. \u0438\u043c\u0435\u043d\u043d\u043e \u0435\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u043c\u043d\u0435 &#8220;\u043f\u043e\u0431\u0435\u0434\u0438\u0442\u044c&#8221; \u0437\u0430\u0434\u0430\u0447\u0443 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u0432\u0435\u0431-\u0441\u0430\u0439\u0442\u0430. \u0421\u0443\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u044f \u0431\u0443\u0434\u0443 \u0438\u0437\u043b\u0430\u0433\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e &hellip; <a href=\"https:\/\/geckich.space\/?p=90\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Mechanize \u0432 Python \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0432\u0435\u0431-\u0444\u043e\u0440\u043c \u0438 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u043e\u0432<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[10,11],"tags":[],"class_list":["post-90","post","type-post","status-publish","format-standard","hentry","category-linux","category-programming"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/posts\/90","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/geckich.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=90"}],"version-history":[{"count":1,"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/posts\/90\/revisions"}],"predecessor-version":[{"id":1288,"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/posts\/90\/revisions\/1288"}],"wp:attachment":[{"href":"https:\/\/geckich.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=90"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geckich.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=90"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geckich.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=90"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}