1648
Written by xlingfairy
Saturday, 31 October 2009 14:15
要抓取某个网站的数据,但是该网站不提供列表,只提供了一个按分类查询的功能。
每次查询要先提供近40K(相当的大了,主要是因为 __VIEWSTATE 这个参数,.NET网站都有这个东东)的数据到网站,然后在 302 跳转到某个页面上。
昨天我耗了N长时间在这个上面,我把所有该发送的数据都发送了,但是一直没有发生 302 跳转。
跟踪了很长时间,我发现在 302 跳转之前的那个 Response 发送回来一个名为 ASP.NET_SessionId 的 cookie ,我认为是在请求的时候,没有把这个 cookie 给发送出去的原因,于是就想着怎么在请求的时候,不自动 redirect ,这样就可以在 response 的时取回这个 cookie 了(事实上跟本就没有发生重定向),接着在请求要重定向的地址。。。于是:
req.AllowAutoRedirect = false;
但是结果还是一样, response.StatusCode = OK, 跟本就不是 302
Last Updated ( Saturday, 31 October 2009 14:24 )
|
1057
Written by xlingfairy
Wednesday, 28 October 2009 15:42
抓取某网页的数据后(比如描述),如果照原样显示的话,可能会因为它里面包含没有闭合的HTML标签而打乱了格式,也可能它里面用了比较让人 "费解" 的HTML标签,把预订的格式搅乱. 如果全盘删除里面的 HTML 标签,可能会造成阅读上的困难(比如 a, img 这些标签), 最好是删除一部分,保留一部分.
正则表达式里,判断 包含某些字符串 是非常容易理解的,但是如何判断 不包含某些字符串 (是字符串,不是字符,是某些,不是某个) 确实是个费解的事.
<(?!((/?\s?li)|(/?\s?ul)|(/?\s?a)|(/?\s?img)|(/?\s?br)|(/?\s?span)|(/?\s?b)))[^>]+>
这个正则是判断HTML标签不包含 li / ul / a / img / br / span / b 的,就上面的要求来说,是要 删除 除这里列出的HTML标签,这也是我摸索了很长时间才搞出来的.
Last Updated ( Wednesday, 28 October 2009 16:16 )
790
Written by xlingfairy
Wednesday, 28 October 2009 11:10
以下是PHP Manual 里关于正则表达式式的条件分枝的叙述:
Conditional subpatterns
It is possible to cause the matching process to obey a subpattern conditionally or to choose between two alternative subpatterns, depending on the result of an assertion, or whether a previous capturing subpattern matched or not. The two possible forms of conditional subpattern are
(?(condition)yes-pattern)
(?(condition)yes-pattern|no-pattern)
If the condition is satisfied, the yes-pattern is used; otherwise the no-pattern (if present) is used. If there are more than two alternatives in the subpattern, a compile-time error occurs.
示例:
(?(?=[^a-z]*[a-z])\d{2}-[a-z]{3}-\d{2} | \d{2}-\d{2}-\d{2} )
Last Updated ( Wednesday, 28 October 2009 11:18 )
|
750
Written by xlingfairy
Saturday, 10 October 2009 17:24
//Response.Expires = -1;
//Response.ExpiresAbsolute = DateTime.Now.AddMinutes(-1);
//Response.CacheControl = "no-cache";
//Response.AddHeader("Pragma", "no-cache");
Response.Cache.SetNoStore();
Response.Cache.SetAllowResponseInBrowserHistory(false);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
Response.Cache.SetValidUntilExpires(true);
Response.Cache.SetMaxAge(new TimeSpan(0));
Response.Cache.SetAllowResponseInBrowserHistory(false);
Response.Cache.AppendCacheExtension("post-check=0,pre-check=0");
我都加了一堆这东西,按返回按钮后,验证图依然不刷新. 上面这些代码是加到验证图里的.
IE/ Chrom 下可早就OK了,但是FF 和 OP 就是不行.
下面是FF返回的 Response.header
472
Written by xlingfairy
Tuesday, 08 September 2009 16:44
string query = @"
SELECT
M.*,
(SELECT COUNT(1) FROM CSK_Store_Product WHERE ManufacturerID = M.ManufacturerID) AS CNT
FROM
(
SELECT
ManufacturerID,ManufacturerName,CreatedOn
FROM
CSK_Store_Manufacturer
WHERE
ManufacturerName LIKE '%@MName%'
) M
";
StoredProcedure sp = new StoredProcedure("");
sp.Command.CommandType = CommandType.Text;
sp.Command.CommandSql = query;
sp.Command.AddParameter("@MName", txtManufacturer.Text.Trim());
sp.Execute();
gd1.DataSource = sp.GetDataSet();
gd1.DataBind();
看这一段,你能看出什么问题吗?
Last Updated ( Tuesday, 08 September 2009 16:46 )
|
|
|
|