如何使用请求验证链接

时间:2013-03-04 22:00:41

标签: python beautifulsoup

我正在尝试使用漂亮的汤从链接中提取数据...目前其失败的身份验证如下所示。我如何验证链接,我知道应该登录的服务器...在哪里提供服务器路径以及如何验证链接?

from bs4 import BeautifulSoup as bs
import argparse
import urllib
import urllib2
import getpass
import re
import requests

def update (url):
    print url
    r = requests.get(url)
    html = r.text
    soup = bs(html)
def main ():
    #For logging
    print "test"
    parser = argparse.ArgumentParser(description='This is the update.py script created by test')
    parser.add_argument('-u','--url',action='store',dest='url',default=None,help='<Required> url link',required=True)
    results = parser.parse_args()# collect cmd line args
    url = results.url
    #print url
    update(url)
if __name__ == '__main__':
    main()

错误: -

Traceback (most recent call last):
  File "announce_update2.py", line 24, in <module>
    main()
  File "announce_update2.py", line 22, in main
    update(url)
  File "announce_update2.py", line 11, in update
    r = requests.get(url)
  File "C:\Python27\lib\site-packages\requests-1.1.0-py2.7.egg\requests\api.py", line 55, in get
    return request('get', url, **kwargs)
  File "C:\Python27\lib\site-packages\requests-1.1.0-py2.7.egg\requests\api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Python27\lib\site-packages\requests-1.1.0-py2.7.egg\requests\sessions.py", line 289, in request
    history = [r for r in gen] if allow_redirects else []
  File "C:\Python27\lib\site-packages\requests-1.1.0-py2.7.egg\requests\sessions.py", line 133, in resolve_redirects
    proxies=proxies
  File "C:\Python27\lib\site-packages\requests-1.1.0-py2.7.egg\requests\sessions.py", line 279, in request
    resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)
  File "C:\Python27\lib\site-packages\requests-1.1.0-py2.7.egg\requests\sessions.py", line 374, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python27\lib\site-packages\requests-1.1.0-py2.7.egg\requests\adapters.py", line 213, in send
    raise SSLError(e)
requests.exceptions.SSLError: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

0 个答案:

没有答案