S
S
Sanya Hihi Haha2020-05-30 20:54:27
Python
Sanya Hihi Haha, 2020-05-30 20:54:27

How to convert get form to url?

Ku, there is such a moronic form

<form action="" method="get">
            <input type="hidden" name="sr_angle" value="0"><input type="hidden" name="sr_back" value="clanRace">
<input type="hidden" name="sr_car_id" value="1009752498"><input type="hidden" name="sr_cid" value="585502"><input type="hidden" name="sr_color" value="0"><input type="hidden" name="sr_counter" value="0"><input type="hidden" name="sr_cur_time" value="1590859609"><input type="hidden" name="sr_dx" value="0"><input type="hidden" name="sr_dy" value="-30"><input type="hidden" name="sr_dz" value="1"><input type="hidden" name="sr_fid" value="449701"><input type="hidden" name="sr_filename" value="cartemp/paint_1009847110_1590857777.png"><input type="hidden" name="sr_item_id" value="194"><input type="hidden" name="sr_method" value="clanRace"><input type="hidden" name="sr_noshop" value="0"><input type="hidden" name="sr_return_method" value="map"><input type="hidden" name="sr_scale" value="100"><input type="hidden" name="sr_session_ttl" value="1590860958"><input type="hidden" name="sr_tab" value="aero"><input type="hidden" name="sr_time" value="40"><input type="hidden" name="sr_trycount" value="1070"><input type="hidden" name="sr_ttl" value="308728"><input type="hidden" name="sr_type" value="c"><input type="hidden" name="app_id" value="598747"><input type="hidden" name="authentication_key" value="5b45d57407776dc8eb4eac04f1678b8b"><input type="hidden" name="ext_perm" value="notifications,emails,payments"><input type="hidden" name="is_app_user" value="1"><input type="hidden" name="mobile_spec" value="smartphone"><input type="hidden" name="oid" value="6315664031247459922"><input type="hidden" name="referer_type" value="wo_ref"><input type="hidden" name="session_expire" value="1590940652"><input type="hidden" name="session_key" value="7792507ad9cc27456b9e3a42c3838b2a"><input type="hidden" name="sig" value="500e5f41125b1116ff3a103e2865a3d3"><input type="hidden" name="vid" value="6315664031247459922"><input type="hidden" name="view" value="app_mobile"><input type="hidden" name="window_id" value="CometName_2f24b508c59c828a58e1ea8da53f8685"><input type="hidden" name="sr_sig" value="9f0be65f9207dcf0a23a60d33f8038f5">
                            <button type="submit" class="b-button b-bn-nr-41-btn" id="" onclick="return blockSubmit();">Гонка</button>
                    </form>


What is the correct way to convert it to url using python?
to get
site.ru/index.php?sr_angle=0&sr_back=enterClan&sr_...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2020-05-30
@ValarMayar

import lxml.html
from urllib.parse import urlencode


form = '''<form action="" method="get">
            <input type="hidden" name="sr_angle" value="0"><input type="hidden" name="sr_back" value="clanRace">
<input type="hidden" name="sr_car_id" value="1009752498"><input type="hidden" name="sr_cid" value="585502"><input type="hidden" name="sr_color" value="0"><input type="hidden" name="sr_counter" value="0"><input type="hidden" name="sr_cur_time" value="1590859609"><input type="hidden" name="sr_dx" value="0"><input type="hidden" name="sr_dy" value="-30"><input type="hidden" name="sr_dz" value="1"><input type="hidden" name="sr_fid" value="449701"><input type="hidden" name="sr_filename" value="cartemp/paint_1009847110_1590857777.png"><input type="hidden" name="sr_item_id" value="194"><input type="hidden" name="sr_method" value="clanRace"><input type="hidden" name="sr_noshop" value="0"><input type="hidden" name="sr_return_method" value="map"><input type="hidden" name="sr_scale" value="100"><input type="hidden" name="sr_session_ttl" value="1590860958"><input type="hidden" name="sr_tab" value="aero"><input type="hidden" name="sr_time" value="40"><input type="hidden" name="sr_trycount" value="1070"><input type="hidden" name="sr_ttl" value="308728"><input type="hidden" name="sr_type" value="c"><input type="hidden" name="app_id" value="598747"><input type="hidden" name="authentication_key" value="5b45d57407776dc8eb4eac04f1678b8b"><input type="hidden" name="ext_perm" value="notifications,emails,payments"><input type="hidden" name="is_app_user" value="1"><input type="hidden" name="mobile_spec" value="smartphone"><input type="hidden" name="oid" value="6315664031247459922"><input type="hidden" name="referer_type" value="wo_ref"><input type="hidden" name="session_expire" value="1590940652"><input type="hidden" name="session_key" value="7792507ad9cc27456b9e3a42c3838b2a"><input type="hidden" name="sig" value="500e5f41125b1116ff3a103e2865a3d3"><input type="hidden" name="vid" value="6315664031247459922"><input type="hidden" name="view" value="app_mobile"><input type="hidden" name="window_id" value="CometName_2f24b508c59c828a58e1ea8da53f8685"><input type="hidden" name="sr_sig" value="9f0be65f9207dcf0a23a60d33f8038f5">
                            <button type="submit" class="b-button b-bn-nr-41-btn" id="" onclick="return blockSubmit();">Гонка</button>
                    </form>'''


root = lxml.html.fromstring(form)

data = {}
for el in root.xpath('.//input'):
    data[el.get('name')] = el.get('value')

qstr = urlencode(data)
print(f'site.ru/index.php?{qstr}')

site.ru/index.php?sr_angle=0&sr_back=clanRace&sr_car_id=1009752498&sr_cid=585502&sr_color=0&sr_counter=0&sr_cur_time=1590859609&sr_dx=0&sr_dy=-30&sr_dz=1&sr_fid=449701&sr_filename=cartemp%2Fpaint_1009847110_1590857777.png&sr_item_id=194&sr_method=clanRace&sr_noshop=0&sr_return_method=map&sr_scale=100&sr_session_ttl=1590860958&sr_tab=aero&sr_time=40&sr_trycount=1070&sr_ttl=308728&sr_type=c&app_id=598747&authentication_key=5b45d57407776dc8eb4eac04f1678b8b&ext_perm=notifications%2Cemails%2Cpayments&is_app_user=1&mobile_spec=smartphone&oid=6315664031247459922&referer_type=wo_ref&session_expire=1590940652&session_key=7792507ad9cc27456b9e3a42c3838b2a&sig=500e5f41125b1116ff3a103e2865a3d3&vid=6315664031247459922&view=app_mobile&window_id=CometName_2f24b508c59c828a58e1ea8da53f8685&sr_sig=9f0be65f9207dcf0a23a60d33f8038f5

S
Sergey Tikhonov, 2020-05-30
@tumbler

urlencode

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question