抓取维基百科数据时出错 - requests.exceptions.ConnectionError :('Connection aborted。',BadStatusLine(“''”,))

时间:2018-02-17 18:22:29

标签: python connection wikipedia

我在第p = wikipedia.page(line)行收到错误。

  

- requests.exceptions.ConnectionError :('Connection aborted。',BadStatusLine(“''”,))

我的INTERNET连接工作正常 我没弄错我的代码。
请帮忙 !谢谢

import wikipedia
import sys
import os

file_dir = sys.argv[1]
for file_name in os.listdir(file_dir):
    with open(os.path.join(file_dir, file_name)) as fd:
        while True:
            line = fd.readline()
            if len(line) == 0:
                break
            line = line.strip()
            if len(line) == 0:
                continue

            p = wikipedia.page(line)
            f = open("/home/data/"+file_name,"a")
        print line
        f.write(line)
        f.write("***")
            try:
            data = p.content 
            data = data.encode("utf8")
            f.write(data)
            print " DONE"
            f.write("\n")
        except: 
            print " NOT done"
            continue

0 个答案:

没有答案