|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #获得贴吧的标题
- import urllib.request
- import re
- def url_open(url):
- #伪造headers 防止屏蔽
- head = {}
- head['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'
- req = urllib.request.Request(url,headers=head)
- response = urllib.request.urlopen(req)
- html = response.read().decode('utf-8')
- return html
- def GetTitle(html):
- info = re.findall(r'target="_blank">(*)</a>',html)
- for title in info:
- print(title)
- if __name__=='__main__':
- for i in range(5):
- ii = (i+1)*50
- print(ii)
- url = "http://tieba.baidu.com/f?kw=%E5%B1%B1%E4%B8%9C%E9%B2%81%E8%83%BD&ie=utf-8&pn=" + str(ii)
- GetTitle(url_open(url))
- print("__________________________________________")
复制代码
是不是我的正则表达式写错了????
|
|