使用Golang扫描网页

时间:2016-06-06 13:57:12

标签: http go

我想扫描任何网页上可用的所有内容,然后一旦完成,我想将一些字符串与该网页上的内容进行比较。如果有一些共同点,我想打印它是正确的网页。 例如:当您进入google.com时,会出现“我感觉很幸运”按钮。在我的代码中,我有一个相同的字符串,我想将我的字符串与屏幕上写的文本进行比较。如果他们最终相同,我将打印“正确的网站”。 我怎么能这样做?

1 个答案:

答案 0 :(得分:5)

net/http是一个好的开始。

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

<b:bean id="passwordEncoder"
    class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" />

<b:bean id="accessDecisionManager"
    class="org.springframework.security.access.vote.AffirmativeBased">
    <b:property name="allowIfAllAbstainDecisions" value="false" />
    <b:constructor-arg>
        <b:list>
            <b:bean class="tool.security.RightVoter" />
        </b:list>
    </b:constructor-arg>
</b:bean>

<authentication-manager alias="authenticationManager">
    <authentication-provider ref="loginAuthenticationProvider" />
</authentication-manager>

<b:bean id="authenticationProcessingFilter"
    class="tool.security.AuthenticationProcessingFilter">
    <b:constructor-arg value="/processLogin" /> <!-- defaultFilterProcessesUrl -->
    <b:property name="authenticationManager" ref="authenticationManager" />
    <!-- <b:property name="filterProcessesUrl" value="/processLogin" /> -->
    <b:property name="authenticationSuccessHandler">
        <b:bean
            class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
            <b:property name="alwaysUseDefaultTargetUrl" value="true" />
            <b:property name="defaultTargetUrl" value="/initLogin" />
        </b:bean>
    </b:property>
    <b:property name="authenticationFailureHandler">
        <b:bean class="tool.security.LoginFailureHandler">
            <b:property name="redirectUrl" value="/login" />
        </b:bean>
    </b:property>
</b:bean>

<b:bean id="loginExistsFilter" class="tool.security.LoginExistsFilter">
    <b:property name="loginUrl" value="/login" />
</b:bean>

<b:bean id="authenticationEntryPoint"
    class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
    <b:constructor-arg value="/login" /> <!-- loginFormUrl -->
</b:bean>

<b:bean id="loginAuthenticationProvider"
    class="tool.security.LoginAuthenticationProvider">
    <b:property name="loginService" ref="loginService" />
</b:bean>

<b:bean id="loginService" class="tool.security.LoginServiceImpl">
    <b:property name="userDao" ref="userDao" />
    <b:property name="userTF" ref="userTF" />
    <b:property name="passwordEncoder" ref="passwordEncoder" />
</b:bean>

<b:bean id="userDao" class="tool.user.impl.MongoUserDao"></b:bean>
<b:bean id="userTF" class="tool.user.UserTFImpl"></b:bean>

<http security="none" pattern="/css/**" />
<http security="none" pattern="/js/**" />
<http security="none" pattern="/login" />
<http security="none" pattern="/loginRedirect" />
<http security="none" pattern="/invalidbrowser" />

<http entry-point-ref="authenticationEntryPoint"
    access-decision-manager-ref="accessDecisionManager">
    <session-management invalid-session-url="/login?timeout=1"
        session-fixation-protection="newSession">
        <concurrency-control max-sessions="1"
            error-if-maximum-exceeded="true" />
    </session-management>

    <custom-filter ref="authenticationProcessingFilter"
        position="FORM_LOGIN_FILTER" />
    <custom-filter ref="loginExistsFilter" before="FILTER_SECURITY_INTERCEPTOR" />

    <csrf disabled="true" />

</http>

<global-method-security
    access-decision-manager-ref="accessDecisionManager"
    secured-annotations="enabled" />