Powershell simulates ie Behavior

Source: Internet
Author: User

Introduction: This is a detailed page for powershell to simulate ie behavior. It introduces PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 337679 'rolling = 'no'>

I tried to use curl to simulate post to send Weibo messages to Sina, but I failed to try it several times. See someArticleSo we thought we could use powershell to simulate the action of IE. It is easier to do this.

1. You can use IE to automatically read cookies insteadCodeDirectly set cookie

2 powershell is used to simulate normal user behavior, and the server can hardly prohibit such behavior.

3. The code is simple and easy to modify.

 

The following is the powershell code (manually use IE to log on to Weibo before running, and let ie record the user name and password and record the cookie)

Function navigateie ($ URL)
{
$ Ie = new-object-com "internetexplorer. Application ";
$ Ie. navigate ($ URL );
# $ Ie. Visible = $ true;
[System. Threading. Thread]: Sleep (2000 );
Return $ ie;
}

Function findtag ($ Params)
{
$ Ie = $ Params [0];
$ Tagname = $ Params [1];
$ Contain = $ Params [2];
$ Doc = $ie.doc ument;
$ Tags = @ ($ Doc. getelementsbytagname ($ tagname ));
Foreach ($ tag in $ tags)
{
If ($ tag. outerhtml. Contains ($ contain ))
{
$ Sel = $ tag;
Break;
}
}
Return $ sel;
}

$ Ie = navigateie ("http://weibo.com/12321 ");

$ Talk = findtag ($ IE, "textarea", 'Id = publish_editor ');

$ But = findtag ($ IE, "span", 'class = bgcolorb ');

$ Talk. value = "test ";
$ But. Click ();

 

The main functions are: navigateie and findtag. One function reads to open IE, and one function reads to find tags.

 

The code process is: Open IE, find the input box, enter information, and click Submit.

Concise and clear

 

PS: This code is not targeted at Sina Weibo. It's just an idle experiment.

 

I personally think this method can be used to perform a simulated test for the testers of the website, because this code operation is exactly the same as the behavior operation of the person. It can simulate people's behaviors and be more persuasive. However, we have not encountered any actual use cases yet.

 

 

Author: Xuan Mai blade (yjf512)
(Http://www.cnblogs.com/yjf512)
Copyright: The copyright of this article is shared by the author and the blog. Please refer to the following link for more information.

Love J2EE follow Java Michael Jackson video station JSON online tools

http://biancheng.dnbcw.info/php/337679.html pageno: 9

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.