Python - 发送 __doPostBack(加入 Roblox 中的群组)

Posted

技术标签:

【中文标题】Python - 发送 __doPostBack(加入 Roblox 中的群组)【英文标题】:Python - Sending __doPostBack (To join groups in Roblox) 【发布时间】:2016-02-09 07:34:44 【问题描述】:

Roblox 是一款游戏,您还可以组队(就像其他游戏中的 Clans 一样)。

我正在制作一个程序来遍历这些组页面,并检查它们是否有所有者。如果没有所有者,则加入群组成为所有者。

我这样做是为了从非所有团体收集一些数据。

最后,我希望它在收集到数据后离开小组。

这里是“加入群组”按钮:

<div id="ctl00_cphRoblox_JoinGroup" class="btn-neutral btn-large" onclick="__doPostBack('JoinGroupDiv', 'Click');" style="margin-top: 10px;">
    Join Group
</div>

这是我尝试过的代码的 sn-p:

import requests
s = requests.session()
Join_Group = dict('JoinGroupDiv', 'Click')
s.post('http://www.roblox.com/Groups/Group.aspx?gid=40', data=Join_Group)

我收到以下错误:

Traceback (most recent call last):
  File "C:\Users\User\Desktop\Group.py", line 18, in <module>
    Join_Group = dict('JoinGroupDiv', 'Click')
TypeError: dict expected at most 1 arguments, got 2

我很确定我不应该向页面发送 Post 请求,因为要加入组,它会执行 onClick 事件。

编辑 1:

这是我更新的代码:

import requests
s = requests.session()
Join_Group = "__EVENTTARGET":"ctl00_cphRoblox_JoinGroup", "__EVENTARGUMENT":"JoinGroupDiv"
s.post('http://www.roblox.com/Groups/Group.aspx?gid=40', data=Join_Group)

但我不太清楚要传递什么作为 eventArguement。我没有收到任何错误,但是当我在 Google Chrome 中加载该页面时,它并没有说我已尝试加入。

编辑 2: 我也试过这个:

import requests
s = requests.session()
Join_Group = "__EVENTTARGET":"ctl00_cphRoblox_JoinGroup", "__EVENTARGUMENT":"JoinGroupDiv","Click"
s.post('http://www.roblox.com/Groups/Group.aspx?gid=40', data=Join_Group)

编辑 3: 所以我在这里拥有的是更新后的 Join_Group ,其中包含所有必要的字段,但不是所有信息。我不知道从哪里得到信息。

Join_Group = "__EVENTTARGET":"JoinGroupDiv", "__EVENTARGUMENT":"Click", "__LASTFOCUS":"", "__VIEWSTATE":"a lot of mumbo jumbo", "__VIEWSTATEGENERATOR":"It is 3D1CCC47 but that might change per post", "__EVENTVALIDATION":"some more mumbo jumbo"

这是一个正确的示例 POST,但我不知道它从哪里获得 __VIEWSTATE__VIEWSTATEGENERATOR__EVENTVALIDATION 的信息。

__EVENTTARGET=JoinGroupDiv&__EVENTARGUMENT=Click&__LASTFOCUS=&__VIEWSTATE=fM9l9%2BTw8z%2FRNbMArorqQ7HQ2w3soDiNp5gJOc5sNNQPEzEzApHiWLOHghGcAriUGv6pCVCi15my4%2BUxUozLVQyGx%2Fiq%2FU9BxRdN80kWJgMyiIyZYtSnfsvlFkqmrHaLIMNKag4eYwnKi5K3TP6JpP5xAxfNIOjekh6vpSa84YVL6eOwPsh5vqlHSN9VjFlwjA1r7AJVZkoeVliUz7vpK1f7DM6lDnOWBtFaAc66xxe2SIoLcjdMlfrVJpJADRjLTEfLp6PNARua3FLJKDezN7WOekGOlSIXHHrzAFlyMY0uZflFykzc9E3zE%2FldijdHWJnIoBVNW1c7fl2ehrbbv%2BAQWpeWqMagkuGNWOmFD6SHPixWLVNgNMlVLXrVKtLEMp3jmXLR40vqdv3bpCkJTLqA9M1XpKsBJlX5szlJlqJzYleD8NncUA8sO2sqiRhnk%2BZURIHV0EQRdPdzJIWMuENZZr%2FPKRl6MNekpZHOtF6wcWQYd4oRYptUjwzWQupbovVnaAyehNLMJbJi6sARkiXAQMC1kUyHpMQVrEdC69%2FNPEW8Cy6QIffUW1d0VBzVuK2hNJV1IgsbqEJZ56HXTtQCz4rJRlATwum2%2BcDS1ITfjA1JWuXwkbFON73TDPFsuz4fOhpVdmNvgN%2B%2F9h4YhmlxlsP3Ud%2BIfuPgzm4b%2FymVzdK%2FBOag7SjO9YRbqH6%2BrIXeXUmPf332sRw4twDy6LhqYxQmzBcr%2BLF4O0%2FTWW1N1pbusZ2p5nyVwaQEQd1FFeVTz5UXNvIUqA89x%2FWzrNHRUEdbR4ZQ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0rXy1U6dXW2UMj8FHEJP8pZ6BX5smKqMQaB6JuWP1pZCPgINg%3D%3D&__VIEWSTATEGENERATOR=3D1CCC47&__EVENTVALIDATION=qv5aJzTc3fM%2BcENN%2BTP2DgRs4ocXUM4qLJNP%2FtEv4q0xMardTbzlDm9uqRxoi%2BfRFn8e%2FC0PuVHiCvBR2xRuCXu%2BBQLORcJ%2BQ%2FANICydWIh6GamZbMbX0BfCN%2BuVKQqW8v1HzL9oN9IOmupGv9F%2BvyxGsToAR94w6szmvNNYvcmQKqcflo2K04UZh1lqzC7ScOHIhyMJb4xooM4oTg3qlmISKwYKDPhVgVgzU4zvzFueU2kToA0DykBBodt8%2BJcKHXbxt4UkL%2FBAZvHs-s-rUeFA9OtAECcG4T3r68EB632IBprg8m9uiVX1wP%2BB8yQQdpQjBtYfT9rBHblz1HvaAu1mcRB0E%3D&ctl00%24cphRoblox%24GroupSearchBar%24SearchKeyword=Search+all+groups&ctl00%24cphRoblox%24rbxGroupRoleSetMembersPane%24dlRolesetList=2343447&ctl00%24cphRoblox%24rbxGroupRoleSetMembersPane%24RolesetCountHidden=2&ctl00%24cphRoblox%24rbxGroupRoleSetMembersPane%24currentRoleSetID=2343447&ctl00%24cphRoblox%24GroupWallPane%24GroupWallPager%24ctl01%24PageTextBox=1

编辑 3:

s = requests.session()
login_data = dict(username='USERNAMEHERE', password='PASSWORDHERE')
s.post('https://www.roblox.com/newlogin', data=login_data)

page = s.get('http://www.roblox.com/Groups/Group.aspx?gid=403577')
soup=BeautifulSoup(page.content, "html.parser")
VIEWSTATE=soup.find(id="__VIEWSTATE")['value']
VIEWSTATEGENERATOR=soup.find(id="__VIEWSTATEGENERATOR")['value']
EVENTVALIDATION=soup.find(id="__EVENTVALIDATION")['value']

Join_Group = dict(__EVENTTARGET="JoinGroupDiv", __EVENTARGUMENT="Click", __LASTFOCUS="", __VIEWSTATE=VIEWSTATE, __VIEWSTATEGENERATOR=VIEWSTATEGENERATOR, __EVENTVALIDATION=EVENTVALIDATION)
join = s.post('http://www.roblox.com/Groups/Group.aspx?gid=403577', data=Join_Group)
print join

【问题讨论】:

那些被 ASP.NET 作为隐藏表单域插入到页面中。您需要阅读页面内容并从表单中提取这些值,然后将它们作为字段添加到您的 POST 中。 【参考方案1】:

您的错误是因为这不是有效的dict 构造。您要么需要文字(如 'foo': 'bar'),要么如果使用构造函数,则需要关键字参数 dict(foo='bar')

您应该像 __doPostBack() 所做的那样进行 POST - 回发到已提供服务的同一页面/URL,请参阅 What is a postback?。

要确定实际需要为 POST 设置什么,您应该了解 __doPostBack() 函数。 这些参数用于填充名为__EVENTTARGET__EVENTARGUMENT 的隐藏表单字段。

您可以在此处阅读有关此内容的说明:

http://www.codeproject.com/Articles/667531/doPostBack-function

编辑:还值得注意的是,当以这种方式与应用程序交互时,您还需要了解正在管理并传递给服务器的任何其他状态。有 cookie、viewstate 等需要考虑。最好在浏览器中完成该过程并使用开发人员工具检查/记录请求,以帮助您确定需要哪些数据。

编辑 2: 我看到 Roblox 有一个 API。如果/可能的话,你最好使用它而不是与他们的 UI 交互。

见http://wiki.roblox.com/index.php/Web_APIs#Group_APIs

如果这不能让您访问组列表(我在这里看不到搜索),那么您可能会考虑采用混合方法。

编辑 3:对于抓取类型的方法,您可能需要考虑使用 Beautiful Soup 来解析页面/表单并提取 ASP.NET 添加的值 -

http://www.crummy.com/software/BeautifulSoup/

【讨论】:

我认为事件目标和参数字段值应该与__doPostBack的参数匹配,即JoinGroupDivClick 我的想法更像Join_Group = "__EVENTTARGET":"JoinGroupDiv", "__EVENTARGUMENT":"Click" 这基本上是回发所做的,您可能需要检查返回的响应以获取更多信息。它可能是一个完全呈现的 HTML 视图,但响应中可能提供了一些消息。 我不会说该字段导致错误,它是提交所必需的。最有可能的原因是缺少诸如“视图状态”之类的数据,这是以这种方式与基于浏览器的应用程序交互时出现的问题。您可能需要提取 __EVENTVALIDATION__VIEWSTATE 隐藏表单字段值并将其包含在您的 POST 中。最好在您手动加入组时使用浏览器开发工具捕获浏览器请求,但检查请求您可以看到需要什么。 哦,太好了。是的,那个帖子已经得到了一切:)

以上是关于Python - 发送 __doPostBack(加入 Roblox 中的群组)的主要内容,如果未能解决你的问题,请参考以下文章

__doPostBack方法解析 __VIEWSTATE __EVENTTARGET __doPostBack __EVENTARGUMENT

__doPostBack 未定义

IE10 SCRIPT5009:“__doPostBack”未定义

_doPostBack用法总结

__doPostBack 方法解析

防止 ASP.net __doPostback() 来自 UpdatePanel 中的 jQuery submit()