wkhtmltopdf Log in to asp.net web app

前端 未结 4 1840
北恋
北恋 2021-01-12 09:18

Having a problem with wkhtmltopdf. I\'m using it to take pdf snapshots of pages on a website that has a username/password page. When the .exe runs, I end up with a snapsho

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-12 09:52

    If anyone's still looking for an answer, I'll write up a brief summary of what I did to get it working.

    First, inspect the page you want to log in to, for instance http:/www.example.com/login

    Look for the form surrounding the username/password inputs. In my case, I was logging into a rails form, so I also needed the authenticity token. Once you have the name and values of the log in inputs, you can make the first wkhtmltoimage call like this:

    wkhtmltoimage --cookie-jar my.jar --post username steve --post password iscool http://www.example.com/login dummy.jpg

    In my case of the rails form, I needed to pass the auth_token as a post parameter as well. Then, just re use that cookie jar when accessing the main page you want to view:

    wkhtmltoimage --cookie-jar my.jar http://example.com/myprofile screenshot.jpg

提交回复
热议问题