|
It looks to me as if that library parses the HTML into a Document Object Model that you can navigate and extract any component parts from.
Have a look at the documentation. I'm sure there's a way to extract JSON, you just have to find it. Griff was only giving an example of how useful the library is.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Bear in mind that a large proportion of websites have T+Cs that explicitly stop you doing that.
I used to do a lot of small web-scraping jobs for a variety of clients; first task was always scour the site T+Cs to check it was permitted.
When I was doing it a lot there weren't any 3rd party tools available, so it's just a case of pulling out the parts of the string you want. In your case I'd search for Member 569739 wrote: type="application/ld+json" (either using a simple ".indexOf() " call or using RegEx), check how many such script blocks there were, and continue likewise to pull out the bits I need. Pretty basic string manipulation.
In this case, though, since the whole of what you want is JSON, just load it up using Newtonsoft.JSON and then access the objects directly:
JObject myJsonObject = JObject.Parse(myJsonText);
|
|
|
|
|
The application/ld+json block is meant to be scraped by other sites - at the very least by search engines:
JSON-LD - JSON for Linking Data[^]
I think it's unlikely that the site would include that block if they didn't want anyone to be able to use it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
"meant to be scraped" - yes.
By whom? Always check the T+Cs.
|
|
|
|
|
Thanks folks. yeah it gets more complicated by the fact that there are multiple of those same blocks other than right now the one I want is the third one. That said, after hours of digging, I did find API's that return JSON for this so coding around that as obviously it's going to be a lot cleaner and more reliable. Haven't run the code yet but fingers crossed this works better. Not sure why ABC hides references to their API's like they do.
|
|
|
|
|
Hi friends,
I want to switch the whole DataGridView Left-To-Right so that the first column is in the right side, like what you see in Excel.
How is it possible?
Please Guide me.
Thanks.
|
|
|
|
|
Alex Dunlop wrote: first column is in the right side, like what you see in Excel. I assume you are dealing with binding a DataSet to a DataGridView where you have no control over the Column order.
0) if you set the RightToLeft property of the Form, the DataGridView will show reverse column order.
1) if you set the RightToLeft property of the DataGridView, you reverse the column order.
2) if you have set the AllowUserToOrderColumns to true, the run time user can reorder columns by dragging.
3) you can change column order in code using the DisplayIndex property of the column [^].
Code like this will work, but, you must execute it either after the form calls InitializeComponent(); ... or, in the Shown event of the form:
DataGridViewColumnCollection columns = dataGridView1.Columns;
int nColumns = columns.Count - 1;
for (int i = 0; i <= nColumns; i++)
{
columns[i].DisplayIndex = nColumns - i;
}
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
And last of all you can reconstruct your datasource to match the column order you require and bind that you the DGV.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Hello All,
I am tasked with performing researching of moving on-premise .net websites(4 different websites) to cloud.
I have to perform comparison of Azure, AWS, Google Cloud Service. Is there any other solutions?
What would be the best way to perform this research and document side-by-side pros and cons?
Thank you!!
|
|
|
|
|
I think the best way would be to learn as much as you can about each cloud provider and compare their offerings.
Don't forget the IBM cloud. That leverages their famous Watson technology.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi!
I have a DataGridView in a Windows Form application where I want to localize the columns in the DataGridView. I use the DataGridView 's DataSource property to populate the DataGridView from a list. Therefore the columns in the DataGridView are genereated automatically after the properies in the list.
Here is the code to populate the DataGridView.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var p1 = new Person() { Name = "Foo", Age = 1337 };
var p2 = new Person() { Name = "Bar", Age = 42 };
var people = new List<Person>() { p1, p2 };
dataGridView1.DataSource = people;
}
}
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
} The generated columns in the DataGridView are Name and Age , the same as the properties in the Person class.
I have set the Form's Localizable property to True .
With a Label in the Form, I have verified that I can change the Label's Text property to different values based on the CurrentCulture / CurrentUICulture I set. I switch between different cultures in the Program.cs file:
static class Program
{
[STAThread]
static void Main()
{
var eng = "en";
var swe = "sv-SE";
var culture = eng;
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(culture);
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
} My project have generated Form1.resx and Form1.sv.resx files to handle both English and Swedish. In these files I can find the label's text for the English and Swedish languages accordingly.
I just don't know how to set the DataGridView's column to different languages. Since the columns are not manually created by me I don't have the appropriate values in the Form1.resx and Form1.sv.resx to set the columns based on the selected language.
Is there any solution to this?
|
|
|
|
|
Because of the way DGV columns are created, you are going to have to iterate over them to localize them: [^].
Look at this excerpt from Hans Passant's code in the link:
foreach (DataGridViewColumn col in dgv.Columns) {
resources.ApplyResources(col, col.Name);
}
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Hello,
I have a simple Arduino robot that communicates through a Bluetooth device (HC-05).
First I made an application in Microsoft Visual C# 2008 that continuously could receive data from the HC-05.
In this Csharp application I just have to place the serialPort1 object and use the serialPort1_DataReceived event. This is working great ! Each time my robot sends three bytes of data, my application successfully receives this.
Now I have Microsoft Visual Studio Professional 2019 and it seems that I could not use the serialPort1 any more...
So I looked on internet and I found a solution with the package "In The Hand Bluetooth from 32feet.NET".
I installed and used successfully this package. Now I can sent and receive data with the HC-05 device.
However, I can only let this work on the event of a button...
So the big problem that I have now is that I cannot receive continuously data like my old application.
I was trying to make a thread that continuously reads data but it doesn't work:
<pre>
FormManager.BluetoothStream = FormManager.bluetoothClient.GetStream();
try
{
Array.Clear(bufferBluetooth, 0, bufferBluetooth.Length);
do
{
FormManager.BluetoothStream.Read(bufferBluetooth, 0, bufferBluetooth.Length);
}
while (FormManager.BluetoothStream.DataAvailable);
System.Diagnostics.Debug.WriteLine("--> bytes received " + bufferBluetooth[0] + " " + bufferBluetooth[1] + " " + bufferBluetooth[2]);
}
catch
{
System.Diagnostics.Debug.WriteLine("Receiving Error");
}
|
|
|
|
|
It looks like you are expecting a continuous stream of data coming in. As soon as your application has caught up (or if there is no data initially to read), your do...while loop will exit and nothing will then read further incoming data. It is improbable that your bluetooth device will be sending data continuously fast enough to satisfy your loop. In comparison, your previous version, being event driven, could wait for further data. You need to see if there is any event driven equivalents in the new package or if there is any way of suspending until new data arrives.
Note: I know nothing about Bluetooth or about the old or new packages that you have been using, so my thoughts could be wrong!
|
|
|
|
|
Hello,
I got it working by using the read and try command.
And this in a loop that I can put later into a thread:
byte[] buffer = new byte[3];
Stream mStream = FormManager.bluetoothClient.GetStream();
while (FormManager.bluetoothClient.Connected)
{
try
{
mStream.Read(buffer, 0, buffer.Length);
System.Diagnostics.Debug.WriteLine("read status "+buffer[0] + " " + buffer[1] + " " + buffer[2] + " --> Status " + FinalResultBT);
}
catch
{
System.Diagnostics.Debug.WriteLine("read status fail ");
}
}
|
|
|
|
|
I'm using a typical 'n-tier' design. In most cases the BL just passes through called to and from the UI and DAL. But I do have some business rules that I'd like to check in the BL. I want to put the code there, versus in the UI because I have a WPF app and a Mobile app both calling the Web API.
So, the question is, how would you handle a rule violation in the BL? Would you throw an exception? Or return a string or other value?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
Richard Deeming wrote: Return an error status code
Thanks. I was leaning in that direction but wanted to get opinions.
I also posted a question in Arch & Design. I would welcome your thouhts on that.
K
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
HI im new to C#
im creating an test app to connect to a local Database, i have created a form which connects to my DB and server, once connected this opens a new form. So far so good. what i need to know now is how do i use the connection in the new form?
thanks
|
|
|
|
|
Exactly how depends on the "relationship" between the two forms.
Have a look at these, one of them will fit your circumstances.
The form that creates an instance of another:
MyForm mf = new MyForm();
mf.Show(); Is the "parent", the other form is the "child".
(This doesn't imply any formal MDI relationship)
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]
But ... you shouldn't create a SqlConnection and "pass it around" your app - that's a bad idea as some operations such as a DataReader that fails to be closed and disposed properly can "block" the connection object from doing anything else. Instead, create a connection string and pass that around (or create it as a public static property and just use it everywhere). Then create your Connection within a using block each time you need one.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thanks for your reply i will take look at the parent child
this is my first app, advancing from hello world . passing the connection string between forms is what i am trying to do. I am a complete Novice.
thanks
|
|
|
|
|
You don't have to "pass" anything. The connection string can be made available to any methods that want it by exposing it as a getter-only property in a static class.
Seriously, if you're moving up from Hello World to this, you may have taken your steps a bit too long.
|
|
|
|
|
If you're creating a connection to the database in your login form to share amongst all other forms, DON'T.
All database operations should be Create Connection as late as possible, do your work, and close connection as early as possible.
DO NOT HOLD A DATABASE CONNECTION OPEN FOR THE LIFE OF YOUR APP.
Also, is a login form really the correct place to open a database connection used by the entire app? Does it have anything to do with the operation of authenticating users in your app?
No, it does not. That is a violation of "separation of concerns". The authentication form should be limited to just that, getting the user credentials and authenticating them. That's it. Nothing else.
The database work should be handled different classes specific to their tasks.
|
|
|
|
|
I Parent, Owner
let me clear something up here:
1) when you declare and instantiate a Form within another Form: they do not have a Parent-Child relationship. It is simply the case at run-time that the instance of the Form that creates the second Form has a valid reference to the instance of the second Form.
2) imho, it's regrettable that it's legal to set a Form to be the Parent of another Form: that leads to a form-within-a-form which is a code smell: you can use the light-weight ContainerControls, like Panel, instead.
3) you can set a Form to be the Owner of another Form ... imho, that is a kind of Parent-Child relationship ... but, all it does is make sure the owned Form appears in front of the owning Form at run-time.
.
II Security in getting and passing data from one Form to another
0) the goal here is to implement security by encapsulation/separation of concerns: all objects/delegates created in the main form Load event do not persist outside that method. the log in form has no "world knowledge" of the main form. there is only one point of access to the log in form in the main form: being able to set the Action delegate 'SendResult in the log in form.
just for the sake of over-kill, we inject the executable code using the lambda format. for a good summary of using Action and Func rather than delegates: [^]
1) code example in a Main Form named Form1's Load EventHandler:
private void Form1_Load(object sender, EventArgs e)
{
LogInForm loginfrm = new LogInForm();
string username, password;
loginfrm.SendResult = (uname, pword) =>
{
username = uname;
password = pword;
};
DialogResult loginResult = loginfrm.ShowDialog();
if (loginResult == DialogResult.OK)
{
}
else if (loginResult == DialogResult.Cancel)
{
}
else if (loginResult == DialogResult.Abort)
{
}
} 2) code in the LogInForm
using System;
using System.Windows.Forms;
namespace YourNameSpace
{
public partial class LogInForm : Form
{
public LogInForm()
{
InitializeComponent();
}
public Action<string, string> SendResult;
private void btnLoginAttempt_Click(object sender, EventArgs e)
{
if (textBox1.Text != "" && textBox2.Text != "")
{
if (SendResult != null)
{
SendResult(textBox1.Text, textBox2.Text);
this.DialogResult = DialogResult.OK;
}
else
{
this.DialogResult = DialogResult.Abort;
}
}
else
{
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
}
} An alternative use of the Delegate/Func: unless the user's log-in data is validated, the log-in form stays open. In real=world code, ypu'd want to keep track of the attempts, and abort the log in after so many attempts;
// in the Main Form
private void Form1_Load(object sender, EventArgs e)
{
LogInForm loginfrm = new LogInForm();
string username, password;
loginfrm.SendResult = SendResult;
DialogResult loginResult = loginfrm.ShowDialog();
if (loginResult == DialogResult.OK)
{
}
else if (loginResult == DialogResult.Cancel)
{
}
else if (loginResult == DialogResult.Abort)
{
}
}
private bool SendResult(string uname, string pword)
{
username = uname;
password - pword;
return false;
} the revised log-in form:
using System;
using System.Windows.Forms;
namespace YourNameSpaace
{
public partial class LogInForm : Form
{
public LogInForm()
{
InitializeComponent();
}
public Func<string, string, bool> SendResult;
private void btnLoginAttempt_Click(object sender, EventArgs e)
{
if (textBox1.Text != "" && textBox2.Text != "")
{
if (SendResult != null)
{
if (SendResult(textBox1.Text, textBox2.Text))
{
this.DialogResult = DialogResult.OK;
}
}
else
{
this.DialogResult = DialogResult.Abort;
}
}
else
{
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
}
}
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
modified 3-Nov-20 21:08pm.
|
|
|
|
|
Thanks, i will have a good read and give that a bash
|
|
|
|