将变量发送到第三方在线表单

huangapple go评论80阅读模式
英文:

Send variable to 3rd party online form

问题

在golang中,有没有一种方法可以将变量传递给Web表单的某个部分?
例如,将"123 Random St."发送到https://www.dominos.com/en/pages/order/#/locations/search/的Street address部分,以此类推?
我找到了pizza_party*,但是使用的GUI已不再可用,我还找到了pizzadash**,但这需要使用信用卡,而我想使用现金。我甚至找到了一些golang的列表,但它们使用的链接不再有效。***
因此,我的目标是:通过dominos网站API在golang中订购披萨!

注意:请提供一个带有示例的包或函数!

注意:我不想制作网络爬虫/数据获取器。

注意:您的答案必须在我提供的链接中的至少一个框上工作。

注意:我想从Linux命令行填写类似于提供的链接的链接。

*https://github.com/coryarcangel/Pizza-Party-0.1.b
**https://github.com/bhberson/pizzadash
***https://golanglibs.com/top?q=pizza

英文:

In golang, is there a way to pipe a variable to part of a web form?
For example, sending "123 Random St." to the Street address part of https://www.dominos.com/en/pages/order/#/locations/search/ and so on? I found pizza_party*, but the GUI used is no longer available, I have also found pizzadash**, but this uses a credit card where I want to use cash. I even found a list of golang ones, but the links that they use doesn't work anymore.***
Therefore, my goal is so: order a pizza in golang through the dominos website API!

NOTE: Please suggest a package or function with example!

NOTE: I do not want to make a web scraper/data getter.

NOTE: Your answer must work on at least one box of my linked website.

NOTE: I want to fill out links similar to the provided link from the linux command line.

*https://github.com/coryarcangel/Pizza-Party-0.1.b
**https://github.com/bhberson/pizzadash
***https://golanglibs.com/top?q=pizza

答案1

得分: 1

这是如何将任何表单值发布到在线表单的方法。前提是你知道服务的POST端点。

func main() {
    resp, err := http.PostForm(targetPostUrlHere,
        url.Values{"Service_Type": {"Delivery"},
            "Address_Type_Select": {"House"},
            "Street": {"123 E 24th St"},
            "Address_Line_2": {"4D"},
            "City": {"New York"},
            "Region": {"NY"},
            "Postal_Code": {"10027"}})
}

注意:字段键和值是估计值。你必须检查表单中实际期望的键名。

在你的情况下,https://www.dominos.com/en/pages/order/ 是表单页面的端点。一旦填写并提交表单,信息将使用POST方法提交到专用的CREATE端点(CRUD中的C),通常可以在<form> HTML标签中找到。

<form action="posttargetendpoint" method="POST">...</form>

一旦POST操作成功,通常一个Web服务会将你重定向到另一个页面。在你的情况下,它是https://www.dominos.com/en/pages/order/#/section/Food/category/AllEntrees/

然而,任何良好的Web服务都不会明确暴露POST端点,因为它是攻击的弱点。你可以通过检查Domino's页面源代码来找出,并相应地调整Go代码中的字段值。

现在,为了创建一个包装PostForm代码的命令行提示符,我建议你查看https://github.com/codegangsta/cli,这是一个非常好的用于创建快速命令行应用程序的包。

英文:

This is how you post any form values onto an online form. Provided you know the POST endpoint of the service.

func main():

   resp, err := http.PostForm(targetPostUrlHere,
	url.Values{&quot;Service_Type&quot;: {&quot;Delivery&quot;}, 
		&quot;Address_Type_Select&quot;: {&quot;House&quot;}, 
		&quot;Street&quot;: {&quot;123 E 24th St&quot;}, 
		&quot;Address_Line_2&quot;: {&quot;4D&quot;}, 
		&quot;City&quot;: {&quot;New York&quot;},
		&quot;Region&quot;: {&quot;NY&quot;},
		&quot;Postal_Code&quot;: {&quot;10027&quot;}})

}

**Note: The field keys and values are guesstimates. You must inspect the actual key names expected in the form.

In your case, https://www.dominos.com/en/pages/order/ is an endpoint for the form page. Once the form is filled and submitted, the information is submitted using POST method akin to the code afore-mentioned to a dedicated CREATE endpoint (C in the CRUD), which normally can be found in the &lt;form&gt; html tag.

&lt;form action=&quot;posttargetendpoint&quot; method=&quot;POST&quot;&gt;...&lt;/form&gt;

Once the POST operation is successful, usually a web service would redirect you to another page. In your case, it is https://www.dominos.com/en/pages/order/#/section/Food/category/AllEntrees/

However, any good web service wouldn't expose the POST endpoint in the clear since it is the vulnerable point of attack. You're welcome to find out by inspect he Domino's page source and adjust the field values in the Go code accordingly.

Now to make a command line prompt to wrap around the PostForm code, I suggest you look into https://github.com/codegangsta/cli which is a very nice package for creating quick command line app.

答案2

得分: 0

我假设你的意思是在用户的代表下,将管道信息从你的后端传递到另一个站点?

在不同域之间传递信息的标准方式是通过HTTP参数,通常是通过GET请求进行传递,但这种能力需要远程站点支持已建立的协议。你还可以使用iframe将另一个站点的页面嵌入到你的页面中,但是你将无法远程交互、调用JS代码,甚至查询页面。出于跨域安全保护的合理原因,这种能力被禁止,一般来说,通过用户的浏览器代表用户进行交互也受到限制,出于安全原因。

然而,如果你想要模拟用户行为,比如使用机器人或网络爬虫从你自己的主机或浏览器进行操作,那就是另外一回事了。有很多框架提供了与页面交互的丰富功能。我建议你查看一下Selenium,它可以作为一个虚拟浏览器。此外,Python还有很多用于处理HTML和结构化数据的库。你可以查看一下Beautiful Soup和Scrapy。

希望对你有所帮助。

英文:

I assume you mean pipe information originating from your backend to another site on behalf of a user?

The standard way of passing information between domains is via HTTP params, usually via a GET request, but this capability would need to be supported by established protocols the remote site. You can also use an iframe to embed the page of another site onto your page, however, you wouldn't be able to remotely interact, call JS code, or even query the page at all. Cross-domain security safeguards justifiably prohibit such capability, and generally speaking, interacting on behalf of the user via their browser is also restricted for security reasons.

However, if you're looking to emulate user behavior such as with a bot or web scraper from your own host or browser then that's a different story. There are tons of frameworks provide rich capability for interacting with a page. I'd recommend checking out Selenium, which acts as a virtual browser. There are also tons of libraries in Python for processing data from HTML and structured data. You might want to check out Beatiful Soup and Scrapy.

Hope this helps.

huangapple
  • 本文由 发表于 2016年3月30日 08:59:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/36297801.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定