#coding:utf-8
import urllib
import urllib2
import re
import sys
import socket
import time
print "Start of work"
filename = "keywords.txt" #关键词文件
fid = open(filename,'r')
all_text = fid.readlines()
NumOutput = open(r'searchnumber.txt','w+')
socket.setdefaulttimeout(6) #设置6s延时
for eachtext in all_text:
eachtext = eachtext.strip('\n')
print eachtext
DataOutput = open(r'searchdata.txt','w+')
flag = 1 #设置标志
while (flag):
try:
response = urllib2.urlopen("http://www.baidu.com/s?"+urllib.urlencode({'wd': eachtext})+"&pn={0}&cl=3&rn=100")
html = response.read()
flag = 0
except socket.error:
errno, errstr = sys.exc_info()[:2]
if errno == socket.timeout:
print "The
Python爬取搜索引擎结果数目
最新推荐文章于 2023-03-12 15:19:11 发布
本文介绍如何使用Python编写爬虫,从搜索引擎中抓取特定关键词的搜索结果数量,探讨了相关的网络请求库和解析技术。
摘要由CSDN通过智能技术生成