如何使用PowerShell InvokeWebRequest Pos

2024-06-02 18:50:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道我们应该增加尽可能多的细节,但我不知道这是如何运作的,所以我的细节将是最低限度的。我不确定这是不是正确的/最好的方法,所以请对我从容不迫。我的情况是:

我想从网页上获取信息。我不能给你这个网页,因为它是公司内部的。基本上,这个网页有一个表单,里面有一堆文本框和几个按钮(其中一个正在提交)。我想通过编程方式(使用PowerShell或者其他类似Python的东西,如果它能更好地工作的话)web请求页面提交一条信息并获得结果。在

我基本上有一个需要循环查看的名字列表。手动完成后,每个名字都会被粘贴到页面上的一个文本框中,点击提交按钮,结果就会弹出。在

我想在名称列表中循环,并对每个项目执行post-webrequest,然后获取结果。这可以用PowerShell完成吗?在

我一直在使用invokewebrequest,但我不完全确定它是如何工作的。我很确定网页上可以执行post请求,因为当我执行

$req = Invoke-WebRequest -URI https://www.foobar.com -Method Post

我没有得到任何错误的网页不接受帖子。有什么建议吗?在

以下是网页上的一些相关代码:

^{pr2}$

我需要向其提供信息的文本框

<input class="k-textbox SearchField" data-summary="Server Name like " id="ServerNameSearchValue" name="ServerNameSearchValue" style="width: 300px;" type="search" value="SOME_SERVER_NAME_FROM_MY_LIST" />

提交表单后,页面上会弹出一个窗口,显示结果。页面不会重新加载或其他任何内容,因此在执行post请求以从新窗口获取信息后,是否需要对页面执行get请求?在


Tags: 方法信息网页表单列表情况页面名字
1条回答
网友
1楼 · 发布于 2024-06-02 18:50:30

我找到了答案

这里是完整的applicationContext.xml文件

希望这能对其他人有所帮助

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">

    <context:component-scan base-package="com.nought">
        <context:exclude-filter type="annotation"
            expression="org.springframework.stereotype.Controller" />
    </context:component-scan>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <bean
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
        id="emf">
        <property name="packagesToScan" value="com.nought.entity" />
        <property name="dataSource" ref="dataSource" />
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
                <prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            </props>
        </property>
        <property name="persistenceProvider">
            <bean class="org.hibernate.jpa.HibernatePersistenceProvider" />
        </property>
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="url" value="jdbc:mysql://localhost:3306/hibernate" />
        <property name="username" value="root" />
        <property name="password" value="" />
    </bean>



    <tx:annotation-driven transaction-manager="transactionManager" />

    <mvc:annotation-driven />

    <jpa:repositories base-package="com.nought.repository"
        entity-manager-factory-ref="emf" />

</beans>

相关问题 更多 >