In a website we have a code like this
<td>TheNumber</td>
<td>ACode</td>
<td style="width:350px;">A Special String For The Number</td>
I want to create an app that the users write the string and the app get 'TheNumber' from website according to the string.
Can we write an app like this in c#?
You can use HTML Agility Pack to manipulate HTML documents.
sample code
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using HtmlAgilityPack;
public class Program
{
public static void Main()
{
// Load
var doc = new HtmlDocument();
doc.LoadHtml(#"<td>TheNumber</td><td>ACode</td><td style='width:350px;'>A Special String For The Number</td>");
var div = doc.DocumentNode.ChildNodes.Where(t => t.InnerText == "A Special String For The Number").ToList().FirstOrDefault();
// Show info
System.Console.WriteLine(div.PreviousSibling.InnerText);
System.Console.WriteLine(div.PreviousSibling.PreviousSibling.InnerText);
}
}
Related
I'm running a basic c# test below. My test is essentially going to go onto www.asos.com then search for a specific item. When the search results are loaded I want to click on the first item that's returned. I tried to use CSS selector to click on the first imagine but I get an exception. Invalid selector.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Interactions;
using System.Threading;
namespace Exercise1
{
class Exercise_2
{
static void Main(string[] args)
{
IWebDriver webDriver = new ChromeDriver();
webDriver.Navigate().GoToUrl("http://www.asos.com/men/");
webDriver.Manage().Window.Maximize();
webDriver.FindElement(By.XPath(".//input[#data-testid='search-input']")).SendKeys("Polo Ralph Lauren Oxford Shirt In Regular Fit Blue");
webDriver.FindElement(By.XPath(".//button[#data-testid='search-button-inline']")).Click();
//*[#id="product-6153807"]/a/div[1]/img Xpath of the image to be clicked on
webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
webDriver.FindElement(By.CssSelector("6153807")).Click();
}
}
}
use the following css selector.
article img
in code,
webDriver.FindElement(By.CssSelector("article img")).Click();
I need help with this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace kbam_.API
{
class filea
{
public static string filea(string url) //this code right here
{
string contents;
var wc = new System.Net.WebClient();
contents = wc.DownloadString(url);
}
}
}
and yes I am authorized by kesbook uk to use this I'm the owner so I can use what I want http://kesbook.cf/autho
If you are querying a a RESTful API I would suggest using the Restsharp nugget package, it is much easier to use.
I have a small problem. I just recently started using Twilio's API to generate a record of messages that was sent to my assigned SID and Auth Token. However my question is how can I generate a text file, based off of what the console writes from the source its addressed to?
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using Twilio;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// Find your Account Sid and Auth Token at twilio.com/user/account
string AccountSid = "X";
string AuthToken = "X";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
// Build the parameters
var options = new MessageListRequest();
options.From = "2015-07-01";
options.To = "2015-07-13";
var messages = twilio.ListMessages(options);
foreach (var message in messages.Messages)
{
Console.WriteLine(message.Body);
Console.Read();
}
}
}
}
Writing to a text file is pretty much boilerplate. The methods are shown here:
https://msdn.microsoft.com/en-us/library/8bh11f1k.aspx
I'm trying to understand how the Swi-cs-pl library works by doing my own little program, but I cannot printout any result from a query based on the example from SWI-Prolog web.
I have this code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SbsSW.SwiPlCs;
namespace HolaMundo
{
class Program
{
static void Main(string[] args)
{
if (!PlEngine.IsInitialized)
{
String[] param = { "-q" }; // suppressing informational and banner messages
PlEngine.Initialize(param);
PlQuery.PlCall("assert(father(hader, nevar))");
PlQuery.PlCall("assert(father(hader, sergio))");
PlQuery.PlCall("assert(brother(nevar, sergio):- father(hader, nevar), father(hader, sergio))");
//How do I write out in a Console the answer for a query like:
// brother(nevar, sergio)
PlEngine.PlCleanup();
}
}
}
}
As I said on my code, I just want to query something basic like: brother(nevar, sergio). and get any answer from Console like true or whatever.
Can anyone help me?
Wrote code as the start to a web crawler that scrapes links from webpage.
Following the instructions from this page:
http://www.dotnetperls.com/scraping-html
I seem to get an error that LinkFinder cannot be found?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Diagnostics;
namespace WebCrawler
{
class Program
{
static void Main(string[] args)
{
WebClient url = new WebClient();
String initialLink = url.DownloadString("http://www.FAKEADDRESS.org.uk/");
for (LinkItem i in LinkFinder.find(initialLink))
{
System.Diagnostics.Debug.WriteLine(initialLink);
}
}
}
}
LinkFinder is a class that is included in the code at that URL you provided. Make sure you also copy that class into your project in some way (a file by itself, in another file, whatever).