|
楼主 |
发表于 2018-8-30 17:23
|
显示全部楼层
Sub Main_fangtianxia1()
Dim i As Long, C As Integer
Dim arr
Dim l_n As Long
Dim liem
Dim a As String, b As String
Dim t
Dim e As Object
Dim ys As Integer
Dim shuzu()
Application.ScreenUpdating = False
t = Timer
Range("a1:J10000").Cells.ClearContents
liem = Array("楼盘名称", "均价", "地址", "装修状态", "户数", "交付时间", "开盘时间", "销售状态", "区域楼盘", "物业类别")
Range("A1:J1") = liem
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "http://newhouse.nb.fang.com/house/s/", False
' .setRequestHeader "If-Modified-Since", "0"
.Send
a = StrConv(.ResponseBody, vbUnicode, &H804)
ys = Split(Split(a, "</span>/")(1), " ")(0)
End With
ReDim shuzu(1 To 20 * ys, 1 To 10)
l_n = Range("A65536").End(xlUp).Row + 1
For C = 1 To ys
Set e = CreateObject("MSXML2.XMLHTTP")
e.Open "GET", "http://newhouse.nb.fang.com/house/s/b9" & C & "/?ctm=1.nb.xf_search.page." & C + 1, False
' e.setRequestHeader "If-Modified-Since", "0"
e.Send
a = StrConv(e.ResponseBody, vbUnicode, &H804) '&H804 简体中文
arr = Split(a, "class=""duibi"" onclick=""add('")
For i = 1 To UBound(arr)
arr(i) = Split(arr(i), "','")(0)
arr(i) = "http://chengshizhiguanghd.fang.com/house/" & arr(i) & "/housedetail.htm"
e.Open "GET", arr(i), False
e.Send
b = StrConv(e.ResponseBody, vbUnicode, &H804)
shuzu(i + (C - 1) * 20, 1) = Split(Split(b, "<span title=""")(1), "楼盘详情")(0)
shuzu(i + (C - 1) * 20, 2) = Split(Split(b, "格:</span><em>" & Chr(10))(1), "</em></div>")(0)
shuzu(i + (C - 1) * 20, 3) = Split(Split(b, "<div class=""list-right-text"">")(2), "</div>")(0)
shuzu(i + (C - 1) * 20, 4) = Split(Split(Split(b, "装修状况:</div>")(1), ">" & Chr(10))(1), "<")(0)
shuzu(i + (C - 1) * 20, 5) = Split(Split(Split(b, "</i>数:</div>")(1), ">")(1), "<")(0)
shuzu(i + (C - 1) * 20, 6) = Split(Split(Split(b, "交房时间:</div>")(1), ">")(1), "<")(0)
shuzu(i + (C - 1) * 20, 7) = Split(Split(Split(b, "盘时间:</div>")(1), ">")(1), "<")(0)
shuzu(i + (C - 1) * 20, 8) = Split(Split(Split(b, "销售状态:</div>")(1), ">" & Chr(10))(1), "<")(0)
shuzu(i + (C - 1) * 20, 9) = Split(Split(b, "楼盘"">")(1), "</")(0)
shuzu(i + (C - 1) * 20, 10) = Split(Split(b, "<div class=""list-right"" title=""")(1), """")(0)
Next
Set e = Nothing
Next
Range("A" & l_n).Resize(UBound(shuzu), 10) = shuzu
Erase shuzu
MsgBox Timer - t
Application.ScreenUpdating = True
End Sub
代码如上,我研究半天都解决不了,请各位大师帮忙啊 |
|