How to get the url of this webpage [closed] - c#

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
My final goal is to write a simple program for myself. It should periodically checks the Thinkpad online store, and will send me an email if it finds any products meeting my criteria.
I've done some research. To get the content of a webpage I can use the code
WebRequest request = WebRequest.Create("http://www.google.com");
WebResponse response = request.GetResponse();
Stream data = response.GetResponseStream();
string html = String.Empty;
using (StreamReader sr = new StreamReader(data))
{
html = sr.ReadToEnd();
}
However for the online store website, I am not able to get the url of my desired page. The website url is in such format
http://outlet.lenovo.com/SEUILibrary/controller/e/outlet_us/LenovoPortal/en_US/catalog.workflow:expandcategory?current-catalog-id=A4A41B4CA13D4754AE2FB1EBF357&current-category-id=908B184AED4F29502E6EB3E1E76AFC13&menu-id=products&ref-id=products#/?page-index=1&page-size=10
I filter the result to only display New W series laptop, but the filter changes doesn't affect the url in the browser address bar. What should I do?

To get anywhere, you should analyze the AJAX calls to the Lenovo Website (using Firebug or Chrome Developer Tools is a good start).
There you see that filter requests are sent to
http://outlet.lenovo.com/SEUILibrary/controller/e/outlet_us/LenovoPortal/en_US/catalog.workflow:GetCategoryFacetResults?q=1
then you'll need to POST some form data to that URL in order to get filtered results (which come back in HTML and you'll have to parse that somehow).
All this you can do by analyzing the AJAX calls.

Related

Access denied when writing to a local path? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
After downloading from my FTP Server, and trying to overwrite that file with an updated one, I get an exception saying: "UnauthorizedAccessException was handled", that, Access to the Path 'C:\My Program\My Program\bin\Debug\App_Data' is denied.
This is what my code looks like:
private void downloadFile () {
WebClient wc = new WebClient();
wc.Proxy = null;
wc.Credentials = new NetworkCredential("user", "pass");
byte[] fileData = wc.DownloadData("ftp://user:pass#mysite.tk/updates/App_Data/log.txt");
File.WriteAllBytes(Application.StartupPath + "\\App_Data", fileData);
}
Am I just missing something to set into the WebClient instance that can allow the 'File.WriteAllBytes' to write the file I'm downloading from my FTP Server to my local machine?
If you think about it, this obviously has nothing to do with WebClient. If you took the same sequence of bytes that you got from WebClient, and tried to write it to the same file, you'd get the same result.
In fact, you'd probably get the same result if you tried to write a single byte, and maybe zero bytes.
Like the exception says,
Access to the Path 'C:\My Program\My Program\bin\Debug\App_Data' is denied
Does the App_Data folder even exist?

How to get Complete QueryString? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
How can I get complete querystring in asp.net?
Suppose a QueryString like this passed to my Login Page.
login.aspx?redirect=cart.aspx&p=1&q=2&r=3
I have to pass parameters p,q and r to Cart.aspx with all of the parameters except redirect.
Login.aspx may handle different querystrings but all parameters except the redirect are to be passed to the redirecting page.(Actually, I know there will be a parameter 'redirect' but can't write code for p,q,and r bcoz it may change in different contexts)
The parameters except 'redirect' will be different in different contexts. The p,q,r are required parameters for cart.aspx. If the redirection is to another page then the parameters may not be p,q,r instead something else like l,m,n
You can use like this
Request.Url.Query
Input like this
Input: http://localhost:96/Cambia3/Temp/Test.aspx?q=item#fragment
Output
You can get the parameters using
string _url=Request.RawUrl.toString();
and
For path ...
string _path = Request.Path.ToString();
string _url = Request.ServerVariables["URL"].ToString();
O/P = /Home/About/
RawURl Returns whole querystring....

How do I insert tabs into strings for a C# console application? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
This console application will write .txt files to disc.
User wants to import these .txt files into Excel such that they are formatted correctly, so I plan to use tabs.
I keep getting this nonsense "Some string /t some other string /t/t some other string". There is no Environment.Tab like there is Environment.NewLine.
How do I get the tabs and not /t into my strings?
I'm sure there's a way and it'll probably be so obvious that I'll have to call myself faint all day on response.
(I'm open to other solutions as well. I might have to use | or some other delimiter/character.)
Tabs in strings are typically written \t, not /t. Are you escaping your string correctly?
If the purpose is to create text files which will eventually be imported int excel why don't you use comma separated values. More info
http://en.wikipedia.org/wiki/Comma-separated_values
Technically there is tab constant in .NET. It is in Microsoft.VisualBasic.dll.
var tab = Microsoft.VisualBasic.Constants.vbTab;
But there is no reason to use vbTab, you can just use \t with the same result.
If you really feel disgusted by this \t question, why not write a simple utility class
public static class MyUtility
{
public static string Tab
{
get{return "\t";}
}
}
now you can use in your code to build your tab separated strings....
string test = "MyFirstString" + MyUtility.Tab + "MySecondString" + MyUtility.Tab .......
but, again, WHY?, there is no reason to not use the predefined standard escape sequence

Why am I getting a FileNotFoundException when the file is there? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I'm trying to save a file to the server and then load into a reader for it to be downloaded. However, I am getting a FileNotFoundExeption. I save to the exact same path, manually open the directory and can see the file there. However, reading it results in the exception. This is my first time trying his - am I doing something wrong?
try
{
using (StreamReader reader = new
StreamReader(HttpContext.Current.Server.MapPath(#"~/Downloads/data.text")))
{
// do something
}
}
catch (Exception)
{
}
Double-check the file name! In one of your comments you used the file name data.txt and not the name data.text. I suppose it's just a typo in your code.

HttpWebRequest.GetResponse() returns error 500 Internal Server Error [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
I'm using HttpWebRequest to make a request to a url:
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(urlAddress);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
but it throws error 500 (Internal Server Error) but when i visit the URLAddress with browser it works fine, urlAddress= www.khademnews.com
it is a simple GET operation but it throws an exception for me how can I solve this?
You might need to set up the user agent as some sites might require it. Also you could use a WebClient to simplify your code:
using (var client = new WebClient())
{
client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0";
string result = client.DownloadString("http://www.khademnews.com");
}
The server might expect other headers as well. You could check with FireBug which headers are sent went you perform the request in your browser and add those headers.

Categories