GetTitleAndUrl
Sub GetTitleAndUrl()
Dim strText As String
Dim i As Long
Dim OneA
Dim IsContent As Boolean
Dim PageIndex As Long
Dim URL As String
For PageIndex = 1 To 10
URL = "http://blog.sina.com.cn/s/articlelist_1511572751_0_" & PageIndex & ".html" With CreateObject("MSXML2.XMLHTTP")
.Open "GET", URL, False
.Send
strText = .responsetext
End With Dim arr() As String
ReDim arr(1 To 2, 1 To 1) As String With CreateObject("htmlfile")
.write strText
i = 0
For Each OneA In .getElementsByTagName("a") s = OneA.href If s Like "*http://blog.sina.com.cn/s/blog_*" Then i = i + 1
ReDim Preserve arr(1 To 2, 1 To i) arr(1, i) = OneA.innerhtml
arr(2, i) = s End If
Next
End With With Sheets("标题")
endrow = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row + 1
Set Rng = .Cells(endrow, 1)
Set Rng = Rng.Resize(UBound(arr, 2), UBound(arr))
Rng.Value = Application.WorksheetFunction.Transpose(arr)
End With Next PageIndex End Sub Sub TestRegReplace()
s = "215MY"
s = RegReplace(s, "[A-Z]")
Debug.Print s
End Sub
Public Function RegReplace(ByVal OrgText As String, ByVal Pattern As String, Optional RepStr As String = "") As String
'传递参数 :原字符串, 匹配模式 ,替换字符
Dim Regex As Object
Dim newText As String
Set Regex = CreateObject("VBScript.RegExp")
With Regex
.Global = True
.Pattern = Pattern
End With
newText = Regex.Replace(OrgText, RepStr)
RegReplace = newText
Set Regex = Nothing
End Function Public Function RegTest(ByVal OrgText As String, ByVal Pattern As String) As Boolean
'传递参数 :原字符串, 匹配模式
Dim Regex As Object
Set Regex = CreateObject("VBScript.RegExp")
With Regex
.Global = True
.Pattern = Pattern
End With
RegTest = Regex.TEST(OrgText)
Set Regex = Nothing
End Function Sub dd()
Debug.Print RegTest("13.", "^\d+?.$")
End Sub
GetTitleAndUrl的更多相关文章
随机推荐
- web前端----JavaScript对象
简介: 在JavaScript中除了null和undefined以外其他的数据类型都被定义成了对象,也可以用创建对象的方法定义变量,String.Math.Array.Date.RegExp都是Jav ...
- python之路----进程二
守护进程 会随着主进程的结束而结束. 主进程创建守护进程 其一:守护进程会在主进程代码执行结束后就终止 其二:守护进程内无法再开启子进程,否则抛出异常:AssertionError: daemonic ...
- Python Web学习笔记之Cookie,Session,Token区别
一.Cookie,Session,Token简介 # 这三者都解决了HTTP协议无状态的问题 session ID or session token is a piece of data that i ...
- bzoj1704 / P2882 [USACO07MAR]面对正确的方式Face The Right Way
P2882 [USACO07MAR]面对正确的方式Face The Right Way $n<=5000$?枚举翻转长度,顺序模拟就ok了 对于每次翻转,我们可以利用差分的思想,再搞搞前缀和. ...
- loj10009 P1717 钓鱼
P1717 钓鱼 贪心+优先队列 先枚举最后走到哪个湖,然后用优先队列跑一遍贪心即可 #include<iostream> #include<cstdio> #include& ...
- Python3.x(windows系统)安装requests库
Python3.x(windows系统)安装requests库 cmd命令: pip install requests 执行结果:
- QtQuickcontrols2控件使用参考
随着Qt的版本升级,其自带的controls控件库也不断升级,目前已经到了2.3的版本.本文通过解读Qt自带的gallery例程,说明新版本controls控件库的相关特性.其具体位置于: 因为相关的 ...
- 20145322 Exp5 Adobe阅读器漏洞攻击
20145322 Exp5 Adobe阅读器漏洞攻击 实验过程 IP:kali:192.168.1.102 windowsxp :192.168.1.119 msfconsole进入控制台 使用命令为 ...
- Git 基础 —— 常见使用场景
Git 基础学习系列 Git 基础 -- 安装 配置 别名 对象 Git 基础 -- 常用命令 Git 基础 -- 常见使用场景 Git基础 -- Github 的使用 突然插入 Bugifx 工作, ...
- 启动jenkins服务错误
背景 重新安装了jenkins,需要启动,使用的yum install安装的,启动jenkins的话只需要执行service jenkins start,但出了两个问题 1. 是提示找不到java 2 ...