ShawnHsia

Analytical Methods & Research of TFDA

Apr 17th, 2022 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. #2022.03.25 test ok
  2.  
  3. from turtle import delay
  4. import requests
  5. from bs4 import BeautifulSoup
  6. import time
  7. import csv
  8. import numpy
  9. #列印標題
  10. """
  11. head=soup.find_all('th')
  12. for xhead in head:
  13.    print(xhead.text, end='   ')
  14. print('\n')
  15. """
  16. for i in range(1,3):
  17.     url='https://www.fda.gov.tw/TC/siteList.aspx?sid=103&pn={}'.format(i)
  18.     #建議檢驗方法網址 https://www.fda.gov.tw/TC/siteList.aspx?sid=1574&pn=1
  19.     #公告檢驗方法網址 https://www.fda.gov.tw/TC/siteList.aspx?sid=103&pn=1
  20.     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"}
  21.     #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"})
  22.     r=requests.get(url,headers=headers,timeout=10)
  23.     r.encoding='utf-8'
  24.     #print(r.status_code)
  25.     #print(r.encoding)
  26.     soup=BeautifulSoup(r.text, 'lxml')
  27.     #print(soup.text)
  28.  
  29.     #表格內容
  30.     for x in range(0, 30, 3):
  31.         y=x+3
  32.         #print(x)
  33.         #print(y)
  34.         result=soup.find_all('td')[x:y]
  35.         #time.sleep(5)
  36.         alist=[]
  37.         for xresult in result:
  38.             alist.append(xresult.text)
  39.         print(alist)
  40.            
  41.         #print(len(alist))
  42.         #print(alist)
  43.         # with open('FDAmethods.txt','a+', encoding='UTF-8') as textfile:
  44.         #     textfile.write(str(alist)+'\n')
  45.  
  46.  
  47.  
Advertisement
Add Comment
Please, Sign In to add comment