コードは機能していますが、これをもっと適切に書く方法、特にifを使う方法のヒントを探しています。あなたは自然界ではプログラマーではないと言うことができます...ただsysの管理者がPythonでちょっとしたことをしています。あなたが提供できるアドバイスをありがとう。Python - BeautifulSoup関数の書き直しに関するヒントをより洗練されたものにする
def findallWileyLinks():
pagebase = 'http://onlinelibrary.wiley.com'
journallist = 'http://onlinelibrary.wiley.com/browse/publications?type=journal&&start=0&resultsPerPage=3000'
inputList = getinputList()
if inputList:
alljournallistsoup = BeautifulSoup(getwebpage(journallist))
if alljournallistsoup:
alljournallisttags = alljournallistsoup.find('ol', attrs={'id' : 'publications'})
for eissn in inputList:
journalatag = alljournallisttags.find('a', attrs={'href' : re.compile(eissn.rstrip() + '$')})
if journalatag:
journalsoup = BeautifulSoup(getwebpage(pagebase + journalatag.get('href') + '/issues'))
if journalsoup:
allvolumetags = journalsoup.find('ol', attrs={'class' : 'issueVolumes'})
volumeatags = allvolumetags.findAll('a')
for volumeatag in volumeatags:
volumesoup = BeautifulSoup(getwebpage(pagebase + volumeatag.get('href')))
if volumesoup:
allissuetags = volumesoup.find('li', attrs={'id' : volumeatag.get('id')[:-5]})
issueatags = allissuetags.findAll('a')[1:]
for issueatag in issueatags:
currentlinksavailiable.append(pagebase + issueatag.get('href') + '\n')
else:
appendlog('eISSN: ' + eissn.rstrip() + ' not found on alljournallist page.')
try:
with open(inputDirectory + selectedPublisher + '_currentlinksavailiable.txt', 'w') as f:
f.writelines(currentlinksavailiable)
except IOError as e:
appendlog('findallLinks() Operation failed probably when creating the new link text file with error: %s' % e.strerror)
ご意見ありがとうございます。 forの前のifは、inputList = []とcurrentlinksavailiable = []と共に削除されています。これは大きなスクリプトの一部です。これは、特定のサイト運営者のリンクを取得するために書かれています。これが洗練されたら、他の出版社にとってより似通った機能を書くためのテンプレートとして使用します。 – Brad