示例#1
0
        // Threaded function
        private void scrapeBook(string ISBN)
        {
            this.Invoke((MethodInvoker) delegate()
            {
                updateLabel.Text     = ISBN;
                detailsListBox.Text += "Scraping " + ISBN + "...  ";
            });

            AmazonScraper amazon = new AmazonScraper();

            try
            {
                string url  = "https://www.amazon.com/Clash-Kings-Song-Fire-Book/dp/" + ISBN + "/ref=tmm_hrd_swatch_0?_encoding=UTF8&qid=1559015792&sr=8-2";
                string page = amazon.getPage(url);

                Book book = amazon.getBook(ISBN, page);
                pushBookToTable(book);
            }
            catch (Exception ex)
            {
                this.Invoke((MethodInvoker) delegate()
                {
                    detailsListBox.Text += "error: " + ex.Message + "!";
                    errorListText.Text  += ISBN + Environment.NewLine;
                });
            }

            this.Invoke((MethodInvoker) delegate()
            {
                progress.PerformStep();
                detailsListBox.Text += Environment.NewLine;
            });
        }
示例#2
0
        // When the search button is clicked
        private void searchButton_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length != 10)
            {
                return;
            }
            string url = "https://www.amazon.com/Clash-Kings-Song-Fire-Book/dp/" + textBox1.Text + "/ref=tmm_hrd_swatch_0?_encoding=UTF8&qid=1559015792&sr=8-2";

            AmazonScraper scraper = new AmazonScraper();

            // Restart progress bar and update label
            {
                progress.Value   = 0;
                updateLabel.Text = "Downloading webpage...";
                Update();
            }

            // Retrieve the page
            string page = scraper.getPage(url);

            if (page == null)
            {
                showError("ISBN not valid!");

                updateLabel.Text = "Click search to scrape for an ISBN";
                progress.Value   = 0;

                return;
            }

            // Update progress bar and update label
            {
                progress.Value   = 50;
                updateLabel.Text = "Finding information...";
                Update();
            }

            Book book = scraper.getBook(textBox1.Text, page);

            progress.Value = 100;

            if (book == null)
            {
                showError("ISBN not valid!");
                return;
            }

            pushBookToTable(book);

            updateLabel.Text = "Click search to scrape for an ISBN";
        }