且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用jsoup从html中的< form action =中提取链接

更新时间:2023-09-02 18:34:28

The short answer is if you want to add product to the basket you can just visit this URL: https://shop.ccs.com/checkout/cart/addAjax/?product=383628&related_product=&qty=1

The long answer is this site submits a form to an URL which has no real HTML content but uses javascript to process your request further. Jsoup can't handle that but we can cheat and use web browser's debugger to peek what happens next and that's how I obtained the URL above.

You can easily use the same link with different product id and quantity. Remember that if you want to make another request for example to check your basket contents you should also pass cookies obtained from previous request. Without that your basket will always be empty.