0

I want to visit

https://www.ptt.cc/bbs/Gossiping/index.html
but I find it should be over than OpenSSL 1.0.1l so I install brew and upgrade openssl to OpenSSL 1.0.2j 26 Sep 2016, but when I use pycharm to print out and it will return version in OpenSSL 0.9.8zh 14 Jan 2016. I have been reference
Python: SSLError using requests for surveymonkey.com
but it's seen not working,and return [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:645)
import urllib3
import urllib3.request
import requests
import ssl
import requests.packages.urllib3.util.ssl_
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = 'ALL'
try:
    links = ['https://www.ptt.cc/bbs/Gossiping/index' + str(id + 1) + '.html' 
    for id in range(15156)]
    twice_link = []
    data = {"yes": "yes"}
    head = {"User-gent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0"}
    for ind, link in enumerate(links, 0):
       with requests.Session() as s:
          data["from"] = "/bbs/Gossiping/index{}.html".format(ind)
          s.post("https://www.ptt.cc/ask/over18", data=data, headers=head)
          res = s.get(link, headers=head)
          soup = BeautifulSoup(res.content,"html.parser")
          data_title = soup.select("div.title")
          data_date = soup.select("div.date") 
          data_author =soup.select("div.author")  
          data_times = soup.select("div.nrec")  
except Exception as e:
    print(ssl.OPENSSL_VERSION)
    print(str(e))
Community
  • 1
  • 1
Roy Wu
  • 71
  • 1
  • 9
  • 1
    You've left something important out of your code. As written, it initializes a few variables and exits without doing anything -- it cannot generate an error. –  Nov 09 '16 at 04:53
  • I hide some belong under program for ind, link in enumerate(links, 0): with requests.Session() as s: data["from"] = "/bbs/Gossiping/index{}.html".format(ind) s.post("https://www.ptt.cc/ask/over18", data=data, headers=head) res = s.get(link, headers=head) soup = BeautifulSoup(res.content,"html.parser") data_title = soup.select("div.title") data_date = soup.select("div.date") data_author =soup.select("div.author") – Roy Wu Nov 09 '16 at 05:40
  • 1
    Include your code in your question -- use the "edit" button below your question to add it. It's impossible to read in a comment; the formatting is lost. –  Nov 09 '16 at 05:51
  • @RoyWu - Please edit your question by clicking *Edit*, and don't post it as a comment. You can find the *Edit* link in the bottom left hand corner of the question. As you can see, its not very helpful to add a block of code to a comment. – jww Nov 09 '16 at 05:54
  • Sorry I have been modify – Roy Wu Nov 09 '16 at 08:10

0 Answers0