违反协议(_ssl.c:590)

时间:2016-04-25 20:01:06

标签: python web-scraping

我正在尝试运行一个代码,将搜索字词发送到谷歌并记录谷歌的建议。

import requests
import re
import time
from random import randint
import pandas as pd
from param_config import config
import cPickle

START_SPELL_CHECK="<span class=\"spell\">Showing results for</span>"
END_SPELL_CHECK="<br><span class=\"spell_orig\">Search instead for"

HTML_Codes = (
        ("'", '&#39;'),
        ('"', '&quot;'),
        ('>', '&gt;'),
        ('<', '&lt;'),
        ('&', '&amp;'),
)

def spell_check(s):
    q = '+'.join(s.split())
    time.sleep(  randint(0,2) ) #relax and don't let google be angry
    r = requests.get("https://www.google.co.uk/search?q="+q)
    content = r.text
    start=content.find(START_SPELL_CHECK) 
    if ( start > -1 ):
        start = start + len(START_SPELL_CHECK)
        end=content.find(END_SPELL_CHECK)
        search= content[start:end]
        search = re.sub(r'<[^>]+>', '', search)
        for code in HTML_Codes:
            search = search.replace(code[1], code[0])
        search = search[1:]
    else:
        search = s
    return search ;

searches = [ "metal plate cover gcfi", 'artric air portable", "roll roofing lap cemet", "basemetnt window", "vynal grip strip", "lawn mower- electic" ]
speel_check_search=[]
for i,search in enumerate(searches):
    speel_check_search.append(spell_check(str(search)))

代码运行正常一段时间但是使用大搜索列表代码运行一段时间然后终止,出现以下错误: requests.exceptions.SSLError:违反协议发生了EOF(_ssl.c:590)

0 个答案:

没有答案