[英]Can not get keyword python scrapy crawler
**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,
]
**
在此處輸入圖片描述錯誤截圖
從鍵盤輸入關鍵字,根據關鍵字構造鏈接,然后啟動搜尋器,現在的問題是我訪問關鍵字的方法問題
根據您的錯誤消息NameError: name 'a' is not defined
,似乎您使用的是python 2而不是python 3,如果是這樣,請使用raw_input()
而不是input()
:
command = raw_input("commands:")
raw_input()
返回用戶輸入的字符串,您可以參考此答案以了解有關input
和raw_input
更多詳細信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.