python 获取网页标题,在Python中检索一个网页的标题

I have more than 5000 webpages i want the titles of all of them. In my project i am using the BeautifulSoup html parser like this.

soup = BeautifulSoup(open(url).read())

soup('title')[0].string

But its taking lots of time. Just for the title of a webpage i am reading the entire file and building the parse tree(I thought this is the reason for delay, correct me if i am wrong).

Is there in any other simple way to do this in python.

解决方案

It would certainly be faster if you just used a simple regular expression, BeautifulSoup is pretty slow. You could do something like:

import re

regex = re.compile('

(.*?)', re.IGNORECASE|re.DOTALL)

regex.search(string_to_search).group(1)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值