HtmlAgilityPack XPath This is an unclosed string [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I need to parse a page and get inner text from specified textbox on that page. But, when I compiled this code:
HtmlAgilityPack.HtmlDocument infoDoc = new HtmlAgilityPack.HtmlDocument();
HtmlNode.ElementsFlags["br"] = HtmlElementFlag.Closed;
infoDoc.LoadHtml(#ProblemPageSource.ToString());
HtmlNode bodyGlobal = #infoDoc.DocumentNode.SelectSingleNode(".//body").SelectSingleNode(".//div[#class='global']");
HtmlNode globalRight = #bodyGlobal.SelectSingleNode(".//div[#class='globalRight']");
HtmlNode formPanel = #globalRight.SelectSingleNode(".//form").SelectSingleNode(".//div[#class='panel]");
ProblemCode = #formPanel.SelectNodes(".//div")[0].SelectSingleNode(".//textarea").OuterHtml.ToString(); //And here is now NullRefEx :(
codeEditor.Text = #ProblemCode.ToString();
I had an exception throwed from Xpath with message "this string is unclosed".
And...source of the page I need to parse hosted at GitHub Gist.
UPD: Minimalistic version:
Minimalistic version of the code viewed in the MozDevTools
Can anybody help me please?
P.S. Sorry for my bad english!
P.S.S. When I checked the code by W3C Validator there are no any unclose tags...but many errors (not my problem :) )
P.S.S.S. Yes, I am using CEFsharp to view the pages, and I get sources from him. So, if it uses autocorrection of Html, why this code is broken? :(

Besides the uncolsed single quote in in your ".//div[#class='panel]" you will need to call:
HtmlAgilityPack.HtmlNode.ElementsFlags.Remove("form");
Before you create an instance of your HtmlDocument because form elements are allowed to overlap and thus handled differently, after that you'll be able to deal with forms as any other element.
so the following shall do:
HtmlAgilityPack.HtmlNode.ElementsFlags.Remove("form");
HtmlNode.ElementsFlags["br"] = HtmlElementFlag.Closed;
var infoDoc = new HtmlAgilityPack.HtmlDocument();
infoDoc.LoadHtml(#ProblemPageSource.ToString());
HtmlNode bodyGlobal = infoDoc.DocumentNode.SelectSingleNode("//body//div[#class='global']");
HtmlNode globalRight = #bodyGlobal.SelectSingleNode(".//div[#class='globalRight']");
HtmlNode formPanel = #globalRight.SelectSingleNode(".//form//div[#class='panel']");
var ProblemCode = #formPanel.SelectSingleNode(".//div/textarea").OuterHtml.ToString();

Correct SelectSingleNode(".//div[#class='panel]"); to SelectSingleNode(".//div[#class='panel']");.

Related

MPXJ C# MSPID: Mark task as done (100% complete) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
We're using the C# version of MPXJ, but rather than examining an existing Project file we're using it to produce a new file purely from code (extracting data from a third party system) for import to Project via MSPDIWriter.
The goal is to have Tasks that report as completed in the other system show up with 100% completion and the ✔ checkmark next to them on the Gantt view when the XML is loaded in Project. This is working as expected only when the total Duration assigned to a task is zero days; for any other duration when Project opens the Task's percentage complete is set to 0%.
Our devs aren't Project people, so it's not clear to us which properties will affect this behaviour:
Task childTask = parent.AddTask();
childTask.Name = sourceItem.Title;
Duration duration = Duration.getInstance(sourceItem.Days, TimeUnit.DAYS);
childTask.PercentageComplete = new java.lang.Integer(childItem.PercentageComplete);
childTask.PercentageWorkComplete = childTask.PercentageComplete;
ResourceAssignment assignment = childTask.AddResourceAssignment(resource);
assignment.Work = duration;
assignment.RemainingWork = duration;
assignment.percentageWorkComplete = childTask.PercentageComplete;
childTask.EffortDriven = false;
childTask.Priority = childItem.Priority;
childTask.Duration = duration;
childTask.BaselineDuration = duration;
if (childItem.PercentComplete == 100)
{
childTask.RemainingWork = Duration.getInstance(0, TimeUnit.DAYS);
}
This sample code works through the steps to create a file from scratch with various combinations of un-started, partially complete, and completed tasks both with and without resource assignments. There is a C# version but I must admit that I haven't kept the two in line. The Java version is probably the more complete, hopefully it should be fairly straightforward to get a working C# version.
I'd suggest starting with these samples and generate MSPDI files from them first, verifying that you get the expected result when the files are imported into MS Project. Hopefully you'll then be able to update your code based on the approach taken in the sample files.
One thing to watch for is that there were some improvements made recently to MSPDI generation relating to getting percent complete to appear correctly so it would be worth verifying that you are working with the most recent version of MPXJ (7.9.2 at the time of writing).

Selenium C# Interact with Chrome Microphone Window [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have an application that when initiated, I receive the popup that "https://example.com wants to:"
"Use your microphone"
I have looked at autoit but it has not been helping. I was trying to use an x/y coordinate but no luck. The autoit window info gives me a name and a class but button info is not there.
Anyone have a way around this issue?
Works perfectly:
$WinTitle = "[CLASS:Chrome_WidgetWin_1]"
WinWait($WinTitle)
WinActivate($WinTitle)
ControlSend($WinTitle, "", "", "{TAB}{ENTER}")
Here is how I got around it using AutoIT. Remove one of the Send("+{TAB}") to set it to Block. I tried removing both of these and just using the enter for Allow but it did not work.
Allow Microphone for Chrome:
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=chromeClickAllow.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Sleep(2000)
WinActivate("Tabs Outliner")
WinWait("[CLASS:Chrome_WidgetWin_1]")
Sleep(500)
WinActivate("[CLASS:Chrome_WidgetWin_1]")
Send("+{TAB}")
Send("+{TAB}")
Send("{ENTER}")

C# library to generate ICal (ics) files [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
Is there any API that I can use and post event data to (for example with querystrings) and get back a file that the visitor can download and add to his calender?
I can of course write the script myself, but if there is a open API I could save some time.
You could use iCal4j
You asked for a webservice of some sort, and I do not know of one, but if you are using .NET, you can create your own using this library:
http://www.codeproject.com/KB/vb/vcalendar.aspx
Maybe it's an option for you to generate and send an e-mail to the user containing the appointments you want the to add. By doing this you:
Haven't jo use any API
Use the build in auto-parsing feature of Apple Mail (Mac OS & iOS)
Stay compatible to other users which might not use iCal
I just used DDay.iCal which works fine for C#. You can see some documentation here on how to read/parse from an .ics file, and this is what i used to create a new file, checked it works on Outlook and on the iOS email application:
public static string GetCalendarAsString(string subject, DateTime start, DateTime end,
string location, string timeZoneName)
{
var calendar = new iCalendar();
var timeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName);
calendar.AddTimeZone(iCalTimeZone.FromSystemTimeZone(timeZone));
var evt = new Event
{
Start = new iCalDateTime(start),
End = new iCalDateTime(end),
Location = location,
Summary = subject,
IsAllDay = false
};
calendar.Events.Add(evt);
var serializer = new iCalendarSerializer();
return serializer.SerializeToString(calendar);
}
you can use several other properties, although I only needed these
You can download iCal4J using http://sourceforge.net/projects/ical4j/files/iCal4j/1.0/ical4j-1.0.zip/download

How can I load kongregate chat in my webbrowser? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have a simple program, and I am trying to load the kongregate chat into a WebBrowser, but it is not working...
When I first start it up, it navigates to a game, and then it gives me 4 Script Error, and the chat just sits there saying: "Joining room...". I don't think it is a problem with the browser settings, because it works on internet explorer. Is there something that is messed up with my WebBrowser? I have let it sit there for a few minutes, and it still does not work. I have set the suppressScriptErrors to true and false, and it still does not fix it.
FYI: I am not doing anything bad with my program, like cheating, or spamming, or anything like that, I just want the webpage to show up, and sometimes I like to be able to have things copied, so I put a few TextBoxes to the right of it, so I can paste it into chat, if I won't to post a few things...
This article has the solution to your problem. It appears that the WebBrowser control in Visual Studio launches in IE7 mode by default. That's why you get javescript errors with the control but, not in your browser. I highly suggest you read the article linked that the top. Luckily, there is a fix. The following code was taken from another stackoverflow answer to a question that indirectly addresses your issue. Here is that link, and here is the code.
string installkey = #"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";
string entryLabel = Path.GetFileName(Application.ExecutablePath);
System.OperatingSystem osInfo = System.Environment.OSVersion;
string version = osInfo.Version.Major.ToString() + '.' + osInfo.Version.Minor.ToString();
uint editFlag = (uint)((version == "6.2") ? 0x2710 : 0x2328); // 6.2 = Windows 8 and therefore IE10
RegistryKey existingSubKey = Registry.LocalMachine.OpenSubKey(installkey, false); // readonly key
if (existingSubKey == null) {
existingSubKey = Registry.LocalMachine.CreateSubKey(installkey, RegistryKeyPermissionCheck.Default); // readonly key
}
if (existingSubKey.GetValue(entryLabel) == null) {
existingSubKey = Registry.LocalMachine.OpenSubKey(installkey, true); // writable key
existingSubKey.SetValue(entryLabel, unchecked((int)editFlag), RegistryValueKind.DWord);
}
Also, the article I mentioned up top says that you should create an entry for the VS host process for your app too or it won't work in debug mode. Good luck and I hope this solves your issue!

can't get proper information from amazon.com using c#/htmlagilitpack

I want to get book information such as author name / pages / publish year / etc ...
from amazon using HtmlAgilityPack but seems amazon webpages have some problems and I can't access the appropriate fields.
here is what I've done :
I use Firefox and Firebug + FirePath to retrieve desired XPath and then inside my code I summon HtmlAgilityPack and instruct it to get information using acquired XPath that I've got it from Firebug
but no luck and till now I couldn't access the "Product Details" part of the amazon.com
and this is my XPath (which is working only with HtmlAgilityPack)
HtmlAgilityPack.HtmlNodeCollection cnt = doc.DocumentNode.SelectNodes("//*[#class='content']");
int i=1;
foreach (HtmlAgilityPack.HtmlNode content in cnt)
{
if (i != 3)
{
i++;
continue;
}
if (i == 3) // i==3 means I've reached the product details but I can't go any further :(
{
s = content.SelectSingleNode("").OuterHtml;
// break;
}
}
How can I access Product Details using appropriate understandable XPath for HtmlAgilityPack?
And why does the syntax of Firebug + FirePath XPath is different from HtmlAgilityPack?
As #Mystere said, I suggest using the API. But if you are doing this for test purpose, or just because you want to use web scraping to obtain the info (I'm not sure if Amazon allows it or not. You should check it before doing this), here is the thing:
Why are you doing this?
s = content.SelectSingleNode("").OuterHtml;
The following is what you are looking for in case you want to get the HTML source of that part of the page.
s = content.OuterHtml;
When you are scraping, I suggest you trying to identify the part you need to scrape, and see the particularities of that block of content.
If you use:
var node = doc.DocumentNode.SelectNodes("//td[#class='bucket']/div[#class='content']");
that will give you the Product Details block you are looking for.
If you want to get some fields like Paperback, Publisher, ... you can do:
string paperback = node.SelectSingleNode("./ul/li[1]/text()").InnerText;
string publisher = node.SelectSingleNode("./ul/li[2]/text()").InnerText;
string language = node.SelectSingleNode("./ul/li[3]/text()").InnerText;
...
If you want to be sure that the XPath you are using will be correct for HtmlAgilityPack, open the page on Internet Explorer 8 (or 9) and use the Developer Tools (F12) to get the XPath. The thing is that each browser renders the HTML in a particular way. For example, you will always see <tbody> tags in Firefox right after a <table>, so maybe HtmlAgilityPack doesn't, and that simple detail of adding /tbody/ to your XPath can make your program fail.
Why don't you just use amazon's web service api that is designed to do this?

Categories

Resources