.
....略
<div class="dotted01"></div>
<!--***************大樂透區塊***************-->
<div class="contents_box02">
<div id="contents_logo_04"></div><div class="contents_mine_tx02"><span class="font_black15">107/9/11 第107000077期 </span><span class="font_red14"><a href="Result_all.aspx#02">開獎結果</a></span></div><div class="contents_mine_tx04">開出順序<br/>大小順序<br/>特別號</div><div class="ball_tx ball_yellow">44 </div><div class="ball_tx ball_yellow">25 </div><div class="ball_tx ball_yellow">18 </div><div class="ball_tx ball_yellow">14 </div><div class="ball_tx ball_yellow">16 </div><div class="ball_tx ball_yellow">23 </div><div
class="ball_tx ball_yellow">14 </div><div class="ball_tx ball_yellow">16 </div><div class="ball_tx ball_yellow">18 </div><div class="ball_tx ball_yellow">23 </div><div class="ball_tx ball_yellow">25 </div><div class="ball_tx ball_yellow">44 </div><div class="ball_red">41 </div>
</div>
<div class="dotted02"></div>
....略
import requests
from bs4 import BeautifulSoup
import html5lib
import pprint
reponse=requests.get('https://www.codejudger.com/target/5203.html')
if reponse.status_code==200:
'伺服器正常響應'
reponse.encoding='utf-8' #設定utf-8
html=reponse.text
soup=BeautifulSoup(html,'html5lib')
#使用bs4解析html
root=soup.find_all(class_='contents_box02')
#擷取class=contents_box02 的所有list
letto=root[2]
#其中第3項是大樂透資訊的部分
numbers=[]
print(f'letto={letto}')
#觀察後發現 開獎號碼在class=ball_tx ball_yellow, 特別號在class=ball_red
numbers_tag=letto.find_all(class_="ball_tx ball_yellow")
#開獎順序
special_number=letto.find(class_='ball_red').text.strip()
for i in numbers_tag[:6]:
numbers.append(i.text.strip())
print('大樂透開獎 :')
print('-'*10)
numbers_str=" ".join(numbers)
numbers.sort()
numbers_str2=" ".join(numbers)
print(f'開出順序:{numbers_str}')
print(f'大小順序:{numbers_str2}')
print(f'特別號 :{special_number}')
--------------------------------------('letto=<div class="contents_box02">\n'
' <div id="contents_logo_04"></div><div class="contents_mine_tx02"><span '
'class="font_black15">107/9/11\xa0第107000077期 </span><span '
'class="font_red14"><a href="Result_all.aspx#02">開獎結果</a></span></div><div '
'class="contents_mine_tx04">開出順序<br/>大小順序<br/>特別號</div><div class="ball_tx '
'ball_yellow">44 </div><div class="ball_tx ball_yellow">25 </div><div '
'class="ball_tx ball_yellow">18 </div><div class="ball_tx ball_yellow">14 '
'</div><div class="ball_tx ball_yellow">16 </div><div class="ball_tx '
'ball_yellow">23 </div><div class="ball_tx ball_yellow">14 </div><div '
'class="ball_tx ball_yellow">16 </div><div class="ball_tx ball_yellow">18 '
'</div><div class="ball_tx ball_yellow">23 </div><div class="ball_tx '
'ball_yellow">25 </div><div class="ball_tx ball_yellow">44 </div><div '
'class="ball_red">41 </div>\n'
' </div>')
大樂透開獎 :
----------
開出順序:44 25 18 14 16 23
大小順序:14 16 18 23 25 44
特別號 :41
標籤: 練習
0 個意見:
張貼留言
訂閱 張貼留言 [Atom]
<< 首頁