c# - 使用关键字单击网页上的链接
问题描述
我希望能够打开至尊的网站(www.supremenewyork.com),进入任何一个标签(衬衫、夹克等)并能够输入我要点击的衬衫的关键字,然后让我的程序点击它。
我想出了如何让它自动点击结帐并填写字段。这是我们将使用的随机衬衫的 html。
https://www.supremenewyork.com/shop/all/shirts
我想点击Houndstooth Flannel Zip Up Shirt
红色的
我已经读到您需要使用HTMLAgilityPack
才能输入inner text's
关键字。但我认为你们可以以正确的方式发送给我。
这是HTML
<article><div class="inner-article"><a style="height:150px;" href="/shop/shirts/gsfge9btl/mkza7miyc"><img width="150" height="150" src="//assets.supremenewyork.com/160974/vi/eYFAEBVxJT0.jpg" alt="Eyfaebvxjt0"></a><h1><a class="name-link" href="/shop/shirts/gsfge9btl/mkza7miyc">Houndstooth Flannel Zip Up Shirt</a></h1><p><a class="name-link" href="/shop/shirts/gsfge9btl/mkza7miyc">Red</a></p></div></article>
这是我的代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HtmlAgilityPack;
namespace Supreme
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("https://supremenewyork.com/shop");
}
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("https://www.supremenewyork.com/shop/accessories");
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
foreach (HtmlElement btn in
webBrowser1.Document.GetElementsByTagName("input"))
{
if (btn.GetAttribute("className") == "button")
{
btn.InvokeMember("Click");
}
}
}
private void button2_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("https://supremenewyork.com/shop/all/shirts");
}
private void button3_Click(object sender, EventArgs e)
{
webBrowser1.GoBack();
}
private void button4_Click(object sender, EventArgs e)
{
foreach (HtmlElement btn in
webBrowser1.Document.GetElementsByTagName("a"))
{
if (btn.GetAttribute("className") == "button checkout")
{
btn.InvokeMember("Click");
}
}
}
}
谢谢你!
解决方案
推荐阅读
- vue.js - 在请求成功时有条件地呈现 b-alert
- mysql - nodejs中mysql查询的意外标识符
- javascript - PHP、mySQL、随机问题测验
- python - 如何使用 bump2version 创建自定义版本标签
- .htaccess - 在 .htaccess 中为 Google 字体添加过期标题
- autodesk-designautomation - JSON Files as parameter input using Forge Design Automation
- hibernate - 无法使用连接表的多对多映射保存数据
- c++ - 有例外的 RAII
- swift - 我将如何约束按钮和图像?
- php - 使用您的用户名或电子邮件填写登录字段