How to GET and parse data from website? Unity3D - http

I am new at this and I do not know how to get info from site and show it in UI. I have tried using plugins but do not know how to. I want to get the numbers showing on the site which are constantly updated to be shown in a UI field when refresh button is click. Can someone please help I am stuck over here.
The site is results site which revise the numbers on it daily bases. The numbers are changing and its a active server page.

As Vancete said, WWW could be used to solve this.
Create a Coroutine, load the data from the webpage and then do something with it.
IEnumerator GetDataFromWebpage (string url)
{
WWW webpage = new WWW(url);
while (!webpage.isDone) yield return false;
string content = webpage.text;
. . .
// Do something with <content>
}

You can take a look here:
https://docs.unity3d.com/ScriptReference/WWW.html
So you should create an WWW object with the desired URL, wait for the response, then load the object.text property. After all, do a substring of what you need and you are done!
Feel free to ask if you need some more help.

Related

Goutte / Web Scraping - How to intercept and download a file

Firstly, thanks in advance for your help here, it's really appreciated!
I've successfully managed to get Goutte to authenticate, hit a URL, change a select field and click a submit button.
The page then reloads and as it finishes loading, it downloads a file to the client.
How do I intercept this file within Goutte? I've read as much doco as I can but can't seem to find an answer. I then want to basically hit this file, traverse it and save it locally.
Depending upon the file type, I want to traverse it, or save it locally.
Thanks :-)
It is not easy to achieve this. In my situation, I open the URL where the file is (after authentication) then the server gives the file (as an object of Page), afterwards you can get the content of the page.
// $url contains the path to the file.
$session->visit($url);
$page = $session->getPage();
$saved = file_put_contents($targetFilePath, $page->getContent());
In my case, I am downloading zip file. In your case, probably save it in a temporary location, detect the type then move it to any desired directory.
Hope this helps.

SiteFinity if user logged in

I am new to SiteFinity. This is the first time I have ever seen it.
I am trying to find out how to check to see if the user is logged in and if they are, do not load certain javascript files (we have a conflict that is causing problems with sitefinity's page editor)
So in the header I want to do something like
if(user_logged_in())
... load js file here
Also I am trying to do this in the master template files.
Version 6.1 FYI
You can try:
ClaimsManager.GetCurrentIdentity().IsAuthenticated
This will return whether or not the user is logged in but it sounds like you need to know if they are a backend user so maybe try:
ClaimsManager.GetCurrentIdentity().IsBackendUser
You'll need this using directive:
using Telerik.Sitefinity.Security.Claims;
I think this might work for you. If the user is authenticated it will load you your .js file.
var isValidUser = SecurityManager.AuthenticateUser(UserManager.GetDefaultProviderName(), userName, userPassword, true);
if (isValidUser == UserLoggingReason.Success){
JavaScriptEmbedControl scriptToEmbed = new JavaScriptEmbedControl();
scriptToEmbed.Url = "path-to-file.js";
scriptToEmbed.ScriptEmbedPosition = Telerik.Sitefinity.Web.UI.PublicControls.Enums.ScriptEmbedPosition.InPlace;
this.form1.Controls.Add(scriptToEmbed);
}

Displaying name after login asp.net webmatrix

I built a site using the starter site template in Webmatrix that uses a log in. After a user logs in, it displays near the top "Hello, (email address)!"
Looking at the html code, I see
Hello, <a id="logname" class="email" href="~/Account/Manage" title="Manage">#WebSecurity.CurrentUserName</a>!
I'm just a beginner with asp.net but can work things out following logic, so what I have done is added a 'Name' field to the database where the email and password is stored and edited the registration page so users can enter their name as well, it writes to the database no problems.
Now I assumed it's just a matter of finding where #WebSecurity.CurrentUserName is referring to the user's email address and make it point to the Name field instead. However I've searched high and low and can not seem to find it anywhere.
So my next approach was to use code from a Bakery database tutorial that fetches data from a field and modify it to grab the name and display it where I want, the code I tried to use here:
#foreach(var row in db.Query(selectQueryString))
This appeared to work at first, It displayed "Hello, Ben!" but then if I made any more accounts it started to display them too, so after a while I was getting "Hello, Ben, Steve, Grace, etc..."
Even though I'm a beginner I do realize that this code isn't quite what I need, but something similar that takes that single Name field but only from the currently logged in user... I've googled and searched and seen many people wanting the same thing, except it's using PHP or VB or something that isn't Webmatrix.
If it's a quick answer I'd appreciate the code I need, or otherwise pointed in the right direction, any help would be greatly appreciated. Thanks in advance..
OK ironically I find the solution moments after posting the question, so here goes..
This is the code needed to be put at the very top of the file _SiteLayout.chtml
#{
var authenticatedUser = "";
if (WebSecurity.IsAuthenticated) {
authenticatedUser = WebSecurity.CurrentUserName;
var db = Database.Open("StarterSite");
var UserData = db.QuerySingle("SELECT Name FROM UserProfile WHERE LOWER(Email) = LOWER(#0)", authenticatedUser);
authenticatedUser = UserData.Name;
}
}
StarterSite is the name of the database, and UserProfile is the name of the Table, and I labeled the name field Name (explained for the purpose of beginners like me who might be reading this)
Then in the html markup I changed #WebSecurity.CurrentUserName to #authenticatedUser so now it reads:
Hello, <a id="logname" class="email" href="~/Account/Manage" title="Manage">#authenticatedUser</a>!
resulting in the desired outcome of it now displaying the user's name instead of their email address.

CMS links on frontend not converting ie href=[sitetree_link_id=xx]

An issue has been noticed on one of our old sites running 2.4 where when the user creates a link in the CMS content, selecting an existing page to link to, the link is not being converted to the actual URL on the front end and all links are coming through in the format of <a href="[sitetree_link_id=12]">
What would be causing this and how do I fix it?
The tag looks like it's being set incorrectly. It should be [sitetree_link id=12], not [sitetree_link_id=12].
We later added support to the parser for [sitetree_link,id=12] so that links didn't need to contain spaces, but I can't recall if that's in 2.4 or only 3.0+.
Can you confirm that your WYSIWYG insertion is putting in that errant _? If so, you might want to checkout the handleaction_insert function in tiny_mce_imporvements.js to confirm that it has a line like so:
case 'internal':
href = '[sitetree_link id=' + this.elements.internal.value + ']';
If the inserted links don't actually have the errant _ but they aren't being parsed, then try checking your sapphire/_config.php file for this:
ShortcodeParser::get('default')->register('sitetree_link', array('SiteTree', 'link_shortcode_handler'));
If your site makes changes to the ShortcodeParser at all you might have inadvertently turned off sitetree_link support.
If all of that looks in order, perhaps the ShortcodeParser isn't being called for some reason. In HTMLText::forTemplate(), put a debug statement (I like die("I got here!");) to confirm that HTMLText::forTemplate() is actually getting called. If it's not, you might need to manually call it in some pre-processing of your Content variable. Instead of this:
$content = $this->Content;
Do this:
$content = $this->obj('Content')->forTemplate();
I hope that one of those answers help. Either way, it would be great if you could post back, so we could isolate what caused this. It might help us make the API easier to use in SilverStripe 3.1.

SEO layout of the website

I am making one website about books and the user reaches the book which he/she intends by traversing though the subjects, then categories and then the subcategories.
As usual, I have made pages that use query strings like this
www.mywebsite.com/subjects.aspx?subjectid=10
The subjectid refers to one of the subjects.
The the user selected the categories and then subcategories and reaches the book.Now, everything is referred by it's id and not by it's name.
Now my question is that the Search Engines dont know how many subjeccts are there and the subject names are not understandable from the id(s).
When I tried to use Google Custom Search, and passed on the url of my website it does not go deep to the book level, instead stays on the main url www.mywebsite.com.
There are some website that I have seen have URL like this:
http://dotnetslackers.com/articles/aspnet/Implementing-Search-in-ASP-NET-with-Google-Custom-Search.aspx
Do they really create a seperate aspx page for each and every article ?
I maynot be able to make you people understand what I want coz I just started asp.net so please think that it has got to do with SEO.
If any clarification is need, please comment and will edit the question.
EDIT 1: Just when I posted this question I noted that it has also created a similar type of page:
http://stackoverflow.com/questions/5581873/seo-layout-of-the-website
Now, Is that a new folder "seo-layout-of-the-website" !
EDIT:2 SO it appears that URL Rewriting is what I need. The example given in one tutorial states that for urls like :
http://www.store.com/products.aspx?category=books
http://www.store.com/products.aspx?category=DVDs
http://www.store.com/products.aspx?category=CDs
I can redirect them to
http://www.store.com/products.aspx/Books
http://www.store.com/products.aspx/DVDs
http://www.store.com/products.aspx/CDs
But in my case, I am using Ids, so does that mean that I should use the names (subject.aspx?subjectname=abcd instead of subject.aspx?subjectid=123) ?
URL Rewriting is what you're looking for. So you could convert your URL:
www.mywebsite.com/subjects.aspx?subjectid=10
to:
www.mywebsite.com/subject/10
by adding a route to it. If you're using ASP.NET 4, you can do this easily. In your Global.asax.cs file, define the following in the Application_Start function:
using System.Web.Routing;
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapPageRoute(
"SubjectRoute",
"subject/{subjectId}",
"~/subjects.aspx"
);
}
And in subjects.aspx.cs, get the value with:
if (Page.RouteData.Values["subjectId"] != null)
{
var mySubjectId = Page.RouteData.Values["subjectId"].ToString());
}
No, they don't create new pages for SEO purpose. what most of us do is rewrite the URL rule in htaccess or apache files. I dont know how it works in asp though

Resources