我使用mechanize刮取网站时出错

2024-04-25 03:42:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用python登录this website并获取信息。 当我使用机械化时。我得到了这个错误信息。请帮我解决这个问题。多谢各位

我的代码:

import mechanize
import urllib

site = "https://secure.lme.com/Data/Community/Login.aspx"
br = mechanize.Browser()

#br.set_cookiejar(cookie)
br.set_handle_robots( False )
br.addheaders = [
    ('User-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36'),
    ('Cache-Control', 'max-age=0'),
    ('Referer', 'https://secure.lme.com/Data/Community/Login.aspx'),
    ('Accept-Encoding', 'gzip, deflate'),
    ('Accept-Language', 'zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4'),
    ('Cache-Control','max-age=0')
]
response = br.open(site)
print response

下面列出了错误:

Traceback (most recent call last):
  File "C:\Python2.7.10\project_database\LME_Login.py", line 17, in <module>
    response = br.open(site)
  File "build\bdist.win32\egg\mechanize\_mechanize.py", line 203, in open
    return self._mech_open(url, data, timeout=timeout)
  File "build\bdist.win32\egg\mechanize\_mechanize.py", line 230, in _mech_open
    response = UserAgentBase.open(self, request, data)
  File "build\bdist.win32\egg\mechanize\_opener.py", line 193, in open
    response = urlopen(self, req, data)
  File "build\bdist.win32\egg\mechanize\_urllib2_fork.py", line 344, in _open
    '_open', req)
  File "build\bdist.win32\egg\mechanize\_urllib2_fork.py", line 332, in _call_chain
    result = func(*args)
  File "build\bdist.win32\egg\mechanize\_urllib2_fork.py", line 1170, in https_open
    return self.do_open(conn_factory, req)
  File "build\bdist.win32\egg\mechanize\_urllib2_fork.py", line 1118, in do_open
    raise URLError(err)
URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:590)>

Tags: inpybrbuildselfeggresponseline