简体   繁体   中英

ruby / watir webdriver - url encoding for spaces, etc

I'm trying to follow with Watir links with spaces and "http://"-s in them. Doing it manually I'm able to copy-paste something like that:

http://somewebsite.com/car%20navigation%20systems/products~NS-1~linkin_id-8016137~cid-3220953854?ef_id=test:@a-b

into the browser address bar, and open the proper page. When I assign this string to a variable url_string in ruby code and do "puts url_string" I see that string in exactly this way (with %20-s in it). When I use it with watir webdriver's "b.goto url_string" it shows "car navigation systems" instead of "car%20navigation%20systems" in the browser, and obviously it doesn't work.

When I "require open-uri" and instead of doing "b.goto url_string" use "b.goto URI::encode(url_string)" I see in the browser that %20 was replaced with %2520 ("car%2520navigation%2520systems") – and again it's not working.

What should I do with the strings like that (which works OK with manual copy-pasting into a browser) to properly use them with b.goto?

http://somewebsite.com/car%20navigation%20systems/products~NS-1~linkin_id-8016137~cid-3220953854?ef_id=test:@a-b

http://somewebsite.com/somepage.cmp?bm=513&BEFID=1398&aon=%5E1&MerchantID=26574&crawler_id=1903439&dealId=U4KvhohLLfNITUSw9xH1PA%3D%3D&url=http%3A%2F%2Flink.mercent.com%2Fredirect.ashx%3Fmr%3AmerchantID%3DREI%26mr%3AtrackingCode%3D4B0E6F02-7411-E111-804A-A8C6AF702B72%26mr%3AtargetUrl%3Dhttp%3A%2F%2Fwww.rei.com%2FOM%2Fsku%2F8108320014%253fcm_mmc%253dcse_shopping-_-datafeed-_-product-_-na%26sdc_id%3D%7Bsdc_id%7D&linkin_id=8011139&Issdt=&searchID=On29U8JKSm&DealName=Garmin+Edge+800+Wireless+Bike+Computer+Color+BLACK&dlprc=449.95&AR=23&NG=29&NDP=40&PN=1&ST=7&FPT=DNSR&NDS=&NMS=&MRS=&PD=104443840&brnId=2455&IsFtr=0&IsSmart=0&op=&CM=&RR=23&IsLps=0&code=&acode=602&category=&HasLink=&ND=&MN=&GR=&lnkId=&SKU=8108320014&IsGtb=0&SPT=CROSSGV&MNID=22406&EF=TEST300%3A3&sig=e917ca16cfc85bedd51b2445ee2aa566f1ccc319&CT=14

UPDATE: so far b.goto url_string.gsub("%20", "+") worked for most of the URLs.

This turned out to be working:

url_string = "http://somewebsite.com/car%20navigation%20systems/products~NS-1~linkin_id-8016137~cid-3220953854?ef_id=test:@a-b"
b.goto url_string.gsub("%20", "+")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM