簡體   English   中英

C#單擊臨時電子郵件網站中的驗證鏈接

[英]C# Click an verify link in an temp email website

我正在編寫一個自動創建帳戶的小應用程序。 我使用http://temp-mail.org網站生成電子郵件地址。

目前,在我的代碼中,日志表明已單擊鏈接,但事實並非如此。 我遇到的第一個問題是在注冊后發送了3封電子郵件,結果顯示了以下HTML代碼。 問題都沒有id,唯一的區別是“ title-subject”。

<tbody>
    <tr>
        <td>"PlayStation Network" &lt;sony@email.sonyentertainmentnetwork.com&gt;</td>
        <td>
            <a href="http://temp-mail.org/en/view/e9527b19d5db504182428bac583977fe"
               class="title-subject">Controleer je account.</a>
        </td>
        <td>...</td>
        <td class="text-center">
            <a href="http://temp-mail.org/en/view/e9527b19d5db504182428bac583977fe"
               class="link">
                <span class="glyphicon glyphicon-chevron-right"></span>
            </a>
        </td>
    </tr>
    <tr>
        <td>"PlayStation Network" &lt;Sony@email.sonyentertainmentnetwork.com&gt;</td>
        <td>
            <a href="http://temp-mail.org/en/view/d3b3a892daeb5c99d85f4c5999242664"
               class="title-subject">Je gebruikersnaam is bijg</a>
        </td>
        <td>...</td>
        <td class="text-center">
            <a href="http://temp-mail.org/en/view/d3b3a892daeb5c99d85f4c5999242664"
               class="link">
                <span class="glyphicon glyphicon-chevron-right"></span>
            </a>
        </td>
    </tr>
</tbody>

在電子郵件中,必須單擊一個鏈接,並且該鏈接具有以下HTML

<td align="center"
    width="150"
    height="40"
    bgcolor="#3071a3"
    style="-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; color: #ffffff; display: block;">
    <a href="https://account.sonyentertainmentnetwork.com/liquid/cam/account/email/validate-email.action?service-entity=np&amp;token=YTVhOTc4ZjItMDI230F3cH9ehcugYxy%2BC9YWHgnQ8l8lh2v%2F943yVVYQWQS4XUlJNMHt0cUlVMpBGAdc7TcwraMoF8K6CQr5QsfaDknPNIgmmWUGyM%2FcEF67%2BHk%3D&amp;request_locale=nl_NL"
       style="color: #ffffff; font-size:16px; font-weight: bold; font-family: Arial, Helvetica, sans-serif; font-size:18px; text-decoration: none; line-height:40px; width:100%; display:inline-block">Nu bevestigen</a>
</td>

現在,我嘗試使用以下代碼:

void DoConfirmation()
        {
            Log("Verifying Email...");
            NavigateAndWait("http://temp-mail.org");
            bool RecievedConfEmail = false;

            for (;;)
            {
                if (!RecievedConfEmail)
                {
                    HtmlElementCollection links = _WebDocument.GetElementsByTagName("A");

                    foreach (HtmlElement link in links)
                    {
                        if (link.InnerText.Equals("account"))
                            link.InvokeMember("Click");
                        Log("I clicked that email you asked");
                        RecievedConfEmail = true;
                        break;
                    }
                }
                else
                {
                    HtmlElementCollection links = _WebDocument.GetElementsByTagName("A");

                    foreach (HtmlElement link in links)
                    {
                        if (link.InnerText.Equals("Bevestigen"))
                            link.InvokeMember("Click");
                        Log("I clicked IN the Email #2");
                        return;
                    }
                }
                Wait(25);
            }
        }

因此,我嘗試通過搜索單詞“ account”來捕獲第一個正確的電子郵件,在第二個單詞中使用單詞“ bevestigen”來捕獲。 即使日志顯示鏈接已被單擊,但事實並非如此。

有人可以用更聰明,更強大的方式幫助我,以獲取正確的電子郵件並單擊鏈接嗎?

那是因為即使InnerText不相等( accountBevstigen ),您也正在記錄日志。 看一下你的if塊。 您還退出了foreach ,因此僅查看單個鏈接。 在兩個if語句之后使用{} 例如:

foreach (HtmlElement link in links)
{
    if (link.InnerText.Equals("account"))
    {
        link.InvokeMember("Click");
        Log("I clicked that email you asked");
        RecievedConfEmail = true;
        break;
    }
}

foreach (HtmlElement link in links)
{
    if (link.InnerText.Equals("Bevestigen"))
    {
        link.InvokeMember("Click");
        Log("I clicked IN the Email #2");
        return;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM