【问题标题】:JSOUP Submitting a POST to a formJSOUP 向表单提交 POST
【发布时间】:2015-04-19 16:33:59
【问题描述】:

我目前正在通过为网站编写应用程序来提高我的编程技能。现在我可以通过应用程序登录网页。我现在的重点是让用户通过应用程序更改他/她的个人资料并将其保存到网站。问题是网站上什么都没有发生,我没有收到错误代码或任何东西。

当我单击保存按钮以保存网站上最近的更改时,我收到以下标题消息(通过使用 google chrome f12 -> 网络):

firstname: John
lastname:Random
streetAddress:Woodstreet 12
careOfAddress:
zipCode:417 22
city:Woods
country:US
phone:111122000
languageForeignKey:4FCB3B38F96800010003004E
invoiceDeliveryMethod:email
preferredMessageMethod:sms
save_button:
utf8:✓
authenticity_token:+RadnomKey40134128Notes=

我的方法

public void setUpdatedContactInformation(String cookie, String firstName,
        String lastName, String streeAdress, String coAdress,
        String zipCode, String city, String country,
        String alternativPhone, String language, String deliveryMethod,
        String messageMethod, String token) {
    try {
        Response Jresponse = Jsoup
                .connect(ContactInfoURL).cookie("Website-session", cookie)
                .data("firstname", firstName, "lastname", lastName,
                        "streetAddress", streeAdress, "careOfAddress",
                        coAdress, "zipCode", zipCode, "city", city,
                        "country", country, "phone", alternativPhone,
                        "languageForeignKey", language,
                        "invoiceDeliveryMethod", deliveryMethod,
                        "preferredMessageMethod", messageMethod,
                        "authenticity_token", token)
                .method(Method.POST)
                .execute();

我不知道是否需要令牌,但我还是使用了它。我可以从之前获取令牌,因此它与记录的会话相同。函数接受的每个输入都与表单相同,我只是将名字更改为 Johnnn 以查看是否有效,但网站上没有更改 John。

【问题讨论】:

    标签: java post get web-scraping jsoup


    【解决方案1】:

    修好了!

    页面上有几个按钮(顶部的搜索栏和一些导航按钮)。通过编辑代码并添加我关注的按钮解决了这个问题。新代码:

    esponse Jresponse = .connect(ContactInfoURL).cookie("Website-session", cookie)
                .data("firstname", firstName, "lastname", lastName,
                        "streetAddress", streeAdress, "careOfAddress",
                        coAdress, "zipCode", zipCode, "city", city,
                        "country", country, "phone", alternativPhone,
                        "languageForeignKey", language,
                        "invoiceDeliveryMethod", deliveryMethod,
                        "preferredMessageMethod", messageMethod, "save_button", button,
                        "authenticity_token", token)
                    .method(Method.POST)
                    .execute();
    

    所以基本上通过添加 F12->Chrome 可以捕获的按钮名称来修复它。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-26
      • 2016-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-14
      • 2017-06-27
      相关资源
      最近更新 更多