2017-05-14 8 views
0
**keyword = '' 

'''To obtain keyword''' 
def test():`enter code here` 
    keywords = list() 
    while True: 
     print('what do you want to do?(a: add a key word for searching, q:quit adding words and start)') 
     command = input('command:') 
     if command == 'a': 
      word = input('keyword: ') 
      if word not in keywords: 
       keywords.append(word) 
     elif command == 'q': 
      break 
     else: 
      print('please input a valid command') 
    if len(keywords) == 0: 
     return 
    search_string = '' 
    for keyword in keywords: 
     search_string += keyword 
     search_string += '+' 
    search_string = search_string[:-1] 
    print(search_string) 

    search_url = 'http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&p=1&u=%2Fnetahtml%2FPTO%2Fsearch-' \ 
       'bool.html&r=0&f=S&l=50&TERM1=' + search_string + '&FIELD1=&co1=AND&TERM2=&FIELD2=&d=PTXT' 

    return search_url 
'''Incoming url start the scrapy crawle''' 
class Uspto(scrapy.Spider): 
    name = 'uspto' 
    #allowed_domains = ['http://patft.uspto.gov/'] 
    #start_url = 'http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&p=1&u=%2Fnetahtml%2FPTO%2Fsearch-bool.html&r=0&f=S&l=50&TERM1=water&FIELD1=&co1=AND&TERM2=&FIELD2=&d=PTXT' 

    allowed_domains = ["http://patft.uspto.gov"] 
    keyword = test() 

    start_urls = [ 
     #"http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&p=1&u=%2Fnetahtml%2FPTO%2Fsearch-bool.html&r=0&f=S&l=50&TERM1=python&FIELD1=&co1=AND&TERM2=&FIELD2=&d=PTXT", 
     keyword, 

    ] 
** 

enter image description hereエラーのスクリーンショットが、その後、キーワードの建設リンクに応じてキーボード入力キーワードから、キーワードのpython scrapyクローラ

を取得し、クローラを起動することはできません、問題は現在、キーワード方式の問題に私のアクセスである

:あなたのエラーメッセージ NameError: name 'a' is not definedに基づいて

答えて

0

は、そう、 raw_input()代わりの input()を使用する場合は、代わりのpython 3のPythonの2を使用しているようです
command = raw_input("commands:") 

raw_input()ユーザーが入力した文字列を返します、あなたはinputraw_inputについての詳細を知るためにthis answerを参照することができます。

+0

私の質問にお答えいただきありがとうございます。それは本当にバージョンの質問です。ありがとうございました – Matcha00

+0

解決策であれば、それを受け入れる答え、感謝としてマークしてください:) –

関連する問題