From: ian Date: Sun, 18 Apr 2004 22:22:21 +0000 (+0000) Subject: can put stuff in basket X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=8e2cab6dfa886575d1cdfb450bc97125099cf755;p=trains.git can put stuff in basket --- diff --git a/farnell/farnell-find b/farnell/farnell-find index 81c2ca6..22782bc 100755 --- a/farnell/farnell-find +++ b/farnell/farnell-find @@ -72,6 +72,7 @@ use LWP::UserAgent; use HTTP::Request; use HTTP::Request::Common; use HTTP::Response; +use HTML::Entities; our(@warn); our(@fault); @@ -217,52 +218,77 @@ sub snarf ($;$) { sub cart_add (@) { my (@orderlist) = @_; my ($i, $url, $item, $qty, @submit, $request, $response); - $url= "$urlbase/jsp/op/shoppingbasket.jsp;jsessionid=$jsessionid". - "?_DARGS=/jsp/home/quickbuycontent.jsp"; - @submit= ( -#_DARGS => "/jsp/home/quickbuycontent.jsp", - -'_dyncharset' => 'ASCII', -#'/pf/commerce/PFCartHandler.setOrderSuccessURL' => '/jsp/op/shoppingbasket.jsp', -#'_D:/pf/commerce/PFCartHandler.setOrderSuccessURL' => ' ', -#'/pf/commerce/PFCartHandler.setOrderErrorURL' => '/jsp/op/shoppingbasket.jsp', -#'_D:/pf/commerce/PFCartHandler.setOrderErrorURL' => ' ', -'/pf/commerce/PFCartHandler.addLinesSuccessURL' => '/jsp/op/shoppingbasket.jsp', -'_D:/pf/commerce/PFCartHandler.addLinesSuccessURL' => ' ', -#'/pf/commerce/PFCartHandler.moveToPurchaseInfoErrorURL' => '/jsp/op/shoppingbasket.jsp', -#'_D:/pf/commerce/PFCartHandler.moveToPurchaseInfoErrorURL' => ' ', -#'/pf/commerce/PFCartHandler.addPotentialProductsSuccessURL' => '/jsp/op/shoppingbasket.jsp', -#'_D:/pf/commerce/PFCartHandler.addPotentialProductsSuccessURL' => ' ', -#'/pf/commerce/PFCartHandler.addPotentialProductsErrorURL' => '/jsp/op/shoppingbasket.jsp', -#'_D:/pf/commerce/PFCartHandler.addPotentialProductsErrorURL' => ' ', -#'/pf/commerce/PFCartHandler.fowardOrderSuccessURL' => '/jsp/op/forwardmultistageorder.jsp', -#'_D:/pf/commerce/PFCartHandler.fowardOrderSuccessURL' => ' ', -#'/pf/commerce/PFCartHandler.moveToPurchaseInfoSuccessURL' => 'https://secure.farnell.com/jsp/op/shipping.jsp;jsessionid=UPTT45ICG5DERQFIAEXSFE4AVAAS4IV3', -#'_D:/pf/commerce/PFCartHandler.moveToPurchaseInfoSuccessURL' => ' ', -'/pf/commerce/PFCartHandler.setOrderByCommerceId.x' => '0', -'/pf/commerce/PFCartHandler.setOrderByCommerceId.y' => '0', -'_D:/pf/commerce/PFCartHandler.setOrderByCommerceId' => ' ', -'_DARGS' => '/jsp/home/quickbuycontent.jsp', - - - ); - while (@orderlist) { - ($item, $qty, @orderlist) = @orderlist; - push @submit, - 'k1', $item, - '_D:k1', ' ', - 'k3', $qty, - '_D:k3', ' '; - } + my ($page_output); + $url= "$urlbase/jsp/op/shoppingbasket.jsp;jsessionid=$jsessionid"; get_useragent(); -print STDERR "url $url; @submit.\n"; - $request= POST $url, \@submit; - $useragent->prepare_request($request); -printf STDERR "request %s.\n", $request->as_string; - $response= $useragent->request($request); - check_response($response,$url); + $response= $useragent->get($url); + check_response($response, $url); + $_= $response->content; + if (!eval { + while (@orderlist) { + ($item, $qty, @orderlist) = @orderlist; + m!( +?)(\ +?\ +?\]*\> +?\ +?\ +?\\]*\> +?\ +?\\]*\>\ \;\ +?\ +?)((?:\ +?\ +?\]*\> +?\ +?\ +?\\]*\> +?\ +?\\]*\>\ \;\ +?\ +?)*\ +?\]* class=\"tableheading\"\> +?\<\!--td inset--\> +?\]*\> +?\ +?\
+?Sub Total +?)! + or die "no blanks\n"; + + my ($page_head)= $`.$1; + my ($entry_2alt, $entry_alt2item, $entry_item2qty, $entry_qty2) + = ($2,$4,$5,$6); + my ($this_alt)= !!length $3; + my ($page_tail)= $7.$'; + + $_= $page_head. + $entry_2alt. ($this_alt ? '' : '_alt'). + $entry_alt2item. $item. $entry_item2qty. $qty. $entry_qty2. + ($this_alt ? + $entry_2alt.'_alt'. + $entry_alt2item. $entry_item2qty. 1 . $entry_qty2. + $entry_2alt. + $entry_alt2item. $entry_item2qty. 1 . $entry_qty2 + : ''). + $page_tail; + } + + m!\! or die "no \n"; + $page_output= $`. "\n" . $& . $'; + 1; + }) { + die "$_ huh $@ ?" unless m/\]*\>/; + $page_output= $`.$&. + "

ERRORS FROM FARNELL-FIND:

\n". + "

". + encode_entities($@). + "\n". + "

In output data:

\n". + $'; + } open N, ">tmp.farn.basket.html" or die $!; - print N $response->content or die $!; + print N $page_output or die $!; close N or die $!; exec 'w3m','./tmp.farn.basket.html'; die $!; }