Visit www.163.com, the first page of the column has the local weather forecast. It can be guessed that the weather forecast here should be based on the caller's IP to determine the location of the local weather conditions. Asked some friends, also confirmed this point. The project also needs weather forecast this small column, the colleague has done one (from other sites to crawl), but cannot realize according to the IP display local weather situation, needs the user to choose, moreover crawls the site belongs to the station .... Its reliability is questionable. So the idea of crawling the weather forecast of NetEase ... Analyze the page ... The area that shows the weather forecast is a iframe,iframe embedded in the following link http://news.163.com/util/position1.html, which directly jumps to another link for this address http:// news.163.com/weather/news/qx1/56294.html, this link shows the weather conditions, as shown in figure:
It can be inferred from this that http://news.163.com/util/position1.html is based on the caller's IP to determine the area, and then return to a region corresponding to the location code, such as: 56294 for Chengdu. How to let NetEase to help our site visitors to judge the region, and give weather conditions, and display on their own site page? We have to continue with the analysis. Because http://news.163.com/util/position1.html, this link to a visit to the weather link, and can not view the source. Then guess. There must be something on this page. Helpless under. WebRequest, the following code appears:
The following is a reference fragment:
1<script language= "Javascript" >
2var city = new Array ("Anhui", "Heilongjiang", "Shandong", "Beijing", "Hubei", "Shanxi", "Fujian", "Hunan", "Shaanxi", "Gansu", "Jilin", "Shanghai", "Guangdong", "Jiangsu", "Sichuan", "Guangxi", "Jiangxi", " Tianjin "," Guizhou "," Liaoning "," Tibet "," Hainan "," Inner Mongolia "," Xinjiang "," Hebei "," Ningxia "," Yunnan "," Henan "," Qinghai "," Zhejiang "," Chongqing ");
3var weaths = new Array (' 58321 ', ' 50953 ', ' 54823 ', ' 54511 ', ' 57494 ', ' 53772 ', ' 59134 ', ' 57679 ', ' 57036 ', ' 52889 ', ' 54172 ', ') ' 58367 ', ' 59287 ', ' 58238 ', ' 56294 ', ' 59431 ', ' 58606 ', ' 54527 ', ' 57816 ', ' 54342 ', ' 55591 ', ' 52856 ', ' 53463 ', ' 51463 ', ' 53698 ' , ' 53614 ', ' 56778 ', ' 57083 ', ' 52866 ', ' 58457 ', ' 57516 ');
4
5function Getcookieval (offset) {
6 var endstr = Document.cookie.indexOf (";", offset);
7 if (endstr = = 1)
8 endstr = document.cookie.length;
9 return unescape (document.cookie.substring (offset, endstr));
10}
11function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (I < Clen) {
var j = i + Alen;
if (document.cookie.substring (i, j) = arg)
return Getcookieval (j);
i = document.cookie.indexOf ("", I) + 1;
if (i = = 0)
break;
23}
return "";
25}
26function Setcookie (cookiename,cookievalue,ndays) {
var today = new Date ();
var expire = new Date ();
if (ndays==null | | ndays==0) Ndays=1;
Expire.settime (Today.gettime () + 3600000*24*ndays);
Document.cookie = cookiename+ "=" +escape (cookievalue) + ";p ath=/;d omain=.163.com;expires=" +expire.toGMTString ();
32}
33function Getcityweatherid (cityname) {
for (i=0;i<city.length;i++) {
(city[i]==cityname) {
return weaths[i];
37}
38}
return "54511";
40}
41
42var ntes_weatheraddr = GetCookie ("ntes_weatheraddr");
43if (! NTES_WEATHERADDR) {
var loc = GetCookie ("theaddr");
if (!loc) {
document.write ("<script type= ' text/javascript ' src= ' http://202.108.39.152/ipquery ' ><" + "/script > ");
47}
48}
49</script>
50<script>
51if (! NTES_WEATHERADDR) {
Ntes_weatheraddr=getcityweatherid (Loc);
53}
54window.location.href= "http://news.163.com/weather/news/qx1/" +ntes_weatheraddr+ ". html";
55</script>
56
57