0
私はthis websiteから必要な番号を取得するコードを書きましたが、次に何をするべきかわかりません。Pythonと美味しいスープを使ってウェブサイトのテーブルデータを自分のウェブサイトのテーブルに挿入します
テーブルの番号を一番下に表示します。分娩の容易さ、出生時体重、離乳時体重、年齢、体重、牛乳および総母性のもの。
#!/usr/bin/python
import urllib2
from bs4 import BeautifulSoup
import pyperclip
def getPageData(url):
if not ('abri.une.edu.au' in url):
return -1
webpage = urllib2.urlopen(url).read()
soup = BeautifulSoup(webpage, "html.parser")
# This finds the epd tree and saves it as a searchable list
pedTreeTable = soup.find('table', {'class':'TablesEBVBox'})
# This puts all of the epds into a list.
# it looks for anything in pedTreeTable with an td tag.
pageData = pedTreeTable.findAll('td')
pageData.pop(7)
return pageData
def createPedigree(animalPageData):
''' make animalPageData much more useful. Strip the text out and put it in a dict.'''
animals = []
for animal in animalPageData:
animals.append(animal.text)
prettyPedigree = {
'calving_ease' : animals[18],
'birth_weight' : animals[19],
'wean_weight' : animals[20],
'year_weight' : animals[21],
'milk' : animals[22],
'total_mat' : animals[23]
}
for animalKey in prettyPedigree:
if animalKey != 'year_weight' and animalKey != 'dam':
prettyPedigree[animalKey] = stripRegNumber(prettyPedigree[animalKey])
return prettyPedigree
def stripRegNumber(animal):
'''returns the animal with its registration number stripped'''
lAnimal = animal.split()
strippedAnimal = ""
for word in lAnimal:
if not word.isdigit():
strippedAnimal += word + " "
return strippedAnimal
def prettify(pedigree):
''' Takes the pedigree and prints it out in a usable format '''
s = ''
pedString = ""
# this is also ugly, but it was the only way I found to format with a variable
cFormat = '{{:^{}}}'
rFormat = '{{:>{}}}'
#row 1 of string
s += rFormat.format(len(pedigree['calving_ease'])).format(
pedigree['calving_ease']) + '\n'
#row 2 of string
s += rFormat.format(len(pedigree['birth_weight'])).format(
pedigree['birth_weight']) + '\n'
#row 3 of string
s += rFormat.format(len(pedigree['wean_weight'])).format(
pedigree['wean_weight']) + '\n'
#row 4 of string
s += rFormat.format(len(pedigree['year_weight'])).format(
pedigree['year_weight']) + '\n'
#row 4 of string
s += rFormat.format(len(pedigree['milk'])).format(
pedigree['milk']) + '\n'
#row 5 of string
s += rFormat.format(len(pedigree['total_mat'])).format(
pedigree['total_mat']) + '\n'
return s
if __name__ == '__main__':
while True:
url = raw_input('Input a url you want to use to make life easier: \n')
pageData = getPageData(url)
s = prettify(createPedigree(pageData))
pyperclip.copy(s)
if len(s) > 0:
print 'the easy string has been copied to your clipboard'
私はこのコードを簡単にコピーして貼り付けるために使用しています。私がしなければならないのは、URLを挿入するだけで、クリップボードにその番号が保存されます。
ここで私のウェブサイトでこのコードを使用したいと思います。私は自分のHTMLコードにURLを挿入できるようにしたい、そして、テーブル内の私のページにこれらの番号を表示します。次のように
私の質問は以下のとおりです。
- 私はウェブサイト上でPythonコードを使用する方法を教えてください。
- 収集したデータをHTML形式の表に挿入するにはどうすればよいですか?
サイトではどのようなフレームワークを使用していますか? –
私はこれを複数のウェブサイトに実装したいと考えていました。また、さまざまなタイプのフレームワークを完全には理解していません。私は非常に素人で、私のウェブサイトもそうです。私はこの情報が役立つかどうかわからないが、私はHTML、CSS、およびJavaScriptを使用する –