2023年1月11日 星期三

Python 爬取統一發票號碼

 Python 爬取統一發票號碼

 源自於 https://steam.oxxostudio.tw/category/python/spider/invoice-auto.html






import requests

url = 'https://invoice.etax.nat.gov.tw/index.html'

web = requests.get(url)    # 取得網頁內容

web.encoding='utf-8'       # 因為該網頁編碼為 utf-8,加上 .encoding 避免亂碼


from bs4 import BeautifulSoup

soup = BeautifulSoup(web.text, "html.parser")                    # 轉換成標籤樹

td = soup.select('.container-fluid')[0].select('.etw-tbiggest')  # 取出中獎號碼的位置

ns = td[0].getText()  # 特別獎

n1 = td[1].getText()  # 特獎

# 頭獎,因為存入串列會出現 /n 換行符,使用 [-8:] 取出最後八碼

n2 = [td[2].getText()[-8:], td[3].getText()[-8:], td[4].getText()[-8:]]

print(ns)

print(n1)

print(n2)


>>> %Run invoice_2.py
11174120
59276913
['18079936', '20591738', '64500205']
>>> 


沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...