当我运行此脚本时,错误“wrap_socket”缺失
尝试使用pip命令安装ssl,但每次都失败
import pickle, pdb, traceback
from pymongo import MongoClient
import urllib2, re
from bs4 import BeautifulSoup
import pprint
import socket, ssl
这是我的班级
class AvvoQA(object):
def _init_(self):
self.client=MongoClient('localhost',27017)
self.db=self.client.local
self.collection=self.db.awo
这是数据库插入代码
def ins(self,awo):
client=MongoClient('localhost',27017)
db=client.local
collection=db.awo
collection.insert(awo)
这是主要功能
def awoMain(self):
article_list = []
link = 'https://www.avvo.com/topics/green-cards/advice?question=1'
findFile = urllib2.urlopen(link)
findHtml = findFile.read()
findFile.close()
soup = BeautifulSoup(findHtml, "lxml")
que = soup.findAll('div', attrs={'class' : 'card topic-advice-question-card'})
for div in que:
try:
awo = {}
awo['question'] = div.findAll('a',attrs={'class':'block-link'})['href']
record['desc_link'] = div.find('a')['href']
record = self.getAns(record)
pprint.pprint(awo)
except:
print
print "This articles faces issue "
print traceback.format_exc()
if __name__ == '__main__':
AvvoQA().awoMain()
显示错误
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 803, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 755, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 1156, in connect
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
AttributeError: 'module' object has no attribute 'wrap_socket'