Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #2022.03.25 test ok
- from turtle import delay
- import requests
- from bs4 import BeautifulSoup
- import time
- import csv
- import numpy
- #列印標題
- """
- head=soup.find_all('th')
- for xhead in head:
- print(xhead.text, end=' ')
- print('\n')
- """
- for i in range(1,3):
- url='https://www.fda.gov.tw/TC/siteList.aspx?sid=103&pn={}'.format(i)
- #建議檢驗方法網址 https://www.fda.gov.tw/TC/siteList.aspx?sid=1574&pn=1
- #公告檢驗方法網址 https://www.fda.gov.tw/TC/siteList.aspx?sid=103&pn=1
- headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36 Edg/99.0.1150.46"}
- #response0=urllib.request.urlopen(url, headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36 Edg/99.0.1150.55"})
- r=requests.get(url,headers=headers,timeout=10)
- r.encoding='utf-8'
- #print(r.status_code)
- #print(r.encoding)
- soup=BeautifulSoup(r.text, 'lxml')
- #print(soup.text)
- #表格內容
- for x in range(0, 30, 3):
- y=x+3
- #print(x)
- #print(y)
- result=soup.find_all('td')[x:y]
- #time.sleep(5)
- alist=[]
- for xresult in result:
- alist.append(xresult.text)
- print(alist)
- #print(len(alist))
- #print(alist)
- # with open('FDAmethods.txt','a+', encoding='UTF-8') as textfile:
- # textfile.write(str(alist)+'\n')
Advertisement
Add Comment
Please, Sign In to add comment