百度收录批量查询【python版】
生活随笔
收集整理的這篇文章主要介紹了
百度收录批量查询【python版】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import urllib2
from BeautifulSoup import BeautifulSoup
import random
import time
def checkIndex(url):
url = url.replace('http://', '')
baiduUrl = 'http://www.baidu.com/s?wd=' + url
webPage = urllib2.urlopen(baiduUrl)
webCont = webPage.read()
webCont = webCont.replace('<b>', '').replace('</b>', '')
soup = BeautifulSoup(webCont)
findlist = soup.find('span', {'class': 'g'})
if findlist:
for each in findlist:
if url in unicode(each):
return url
else:
return None
else:
return None
waittime = random.randint(1, 20)
urllist = open('list.txt')
res = open('check.txt', 'w')
for eachurl in urllist.readlines():
indexurl = unicode(checkIndex(eachurl)) + '\n'
res.write(indexurl)
time.sleep(waittime)
urllist.close()
res.close()
print 'over!'
總結
以上是生活随笔為你收集整理的百度收录批量查询【python版】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 图片码制作
- 下一篇: 关于spring MVC中加载多个val