iT邦幫忙

1

初學者 利用python爬蟲網站表格值 顯示空值 找不到問題

  • 分享至 

  • xImage
import requests
from bs4 import BeautifulSoup

url = 'http://price.naif.org.tw/Query/Query_now.aspx'

headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'}

resp = requests.get(url, headers=headers)

# 設定編碼為 utf-8 避免中文亂碼問題
resp.encoding = 'utf-8'

# 根據 HTTP header 的編碼解碼後的內容資料(ex. UTF-8),若該網站沒設定可能會有中文亂碼問題。所以通常會使用 resp.encoding 設定
raw_html = resp.text

# 將 HTML 轉成 BeautifulSoup 物件
soup = BeautifulSoup(raw_html, 'html.parser')

print(soup.select('html > body > #form1 > div.wrap > div.contant > div:nth-child(7) > div > #ContentPlaceHolder_content_GridView_data > tbody > tr:nth-child(4) > td:nth-child(2)'))

上方是我的程式碼,
我要爬蟲的網站:http://price.naif.org.tw/Query/Query_now.aspx
我要爬蟲該表格的值,
https://ithelp.ithome.com.tw/upload/images/20210707/201365797yOZ34S8os.png
但我利用上方的程式碼print出來的值顯示「[]」空值,
嘗試過許多方法結果都一樣,
不知道我是不是缺少什麼,
謝謝!

不明 檢舉
它那個是要用POST請求
你可以用F12去看它需要哪些參數
應該是POST請求,你的URL裡並無查詢用的參數什麼的資料,所以結果空白
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
1
shijung
iT邦新手 3 級 ‧ 2021-07-08 09:04:30
最佳解答

F12 -> NetWork -> Name欄位下找出按查詢的請求 xxx.aspx => 右邊點選Headers=>你會看到Request Type 是 Post 然後找Form Data 把參數丟上去

import requests
from bs4  import BeautifulSoup
payload = {
    '__EVENTTARGET':'',
    '__EVENTARGUMENT':'',
    '__LASTFOCUS':'',
    '_VIEWSTATEGENERATOR': '02BC70F4',
    '__SCROLLPOSITIONX': 0,
    '__SCROLLPOSITIONY': 800,
    '__V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gl2CR7DhOv0m/iDDDyMEQl0womhnETTsBiS4LoJbGzp/VR9PLbHUKjdkddTafr4Yd2tDu4QXw42VyAqNyboI4GkON+gIRoQSUEE6U3lSs0HU3PeCrxRqoNJdFroFoZblO6TS1O8ObYydjpRVdFhCgRKoFkXxgvHrX3z+NmC8Cu8bNaJFRTlDHnc3q9jlx1fbAt5qk9sdeBdXKDZ2gfgaAqv+r8fcSCW+sKOegHMkRBuyUu7Z1u5DB49zqRnSxL1RWrNLS1pNq1J0Kzkd7e5QrzkSANtaECxM5GS0A5MvpX1MKHYinXh3xoSSXRGHXeevlfhi6G0AqErGdp2iDPa/4+HvxQJyNeo4pa2rfqZ+TijV1KhPZ9t112+wKWgCgUx+90LoKanCA5KPcWQfAgoH6KepdFYaEkToqLP8vQk/5Mt1SgLU+UhCEm5dtO/aqHvneN02hRfoErusn7owDi/6EaUR99VWuBLGMeIbAuquA5IigBbI17Rxp7yuFkFI50Mb+9p3THIrOa9ncmClF8noovKG4awSV383ucXO68AYV4R/NAp0Mf1jseZzrICE+kAHE9RDztg5LWrPrAa0v4eW005XcLM4j/U5VK680L6vSj5qzN4MKPJeqofGOT3sknP5NH0RZEqt5a5rKR0Bz9DwotEEVtmE6nxaUjAgbDxxfUOMDkHeZxX3/MLwlCTvwl8r714CO5OwwWsO0xXcjVkWJGCLkFZo/JPVuewb9aXnZN9w6Xmoa1oyZxp76oo1zVd0R0DZfoB3UmUNamD3HRNVx5kgBfsihEKYxpG3AhNbXjSpP/z6HYaLfUNatHlXngJvmXEbz2selvdR6ofLw2q4=',
    'ctl00$ContentPlaceHolder_content$RadioButtonList_resultType':0,
    'ctl00$ContentPlaceHolder_content$uc_timeSelector$time':'RadionButton_year',
    'ctl00$ContentPlaceHolder_content$uc_timeSelector$DropDownList_startYear':2020,
    'ctl00$ContentPlaceHolder_content$uc_timeSelector$DropDownList_endYear':2021,
    'ctl00$ContentPlaceHolder_content$uc_timeSelector$DropDownList_month_startYear':2021,
    'ctl00$ContentPlaceHolder_content$uc_timeSelector$DropDownList_month_startMonth':1,
    'ctl00$ContentPlaceHolder_content$uc_timeSelector$DropDownList_month_endYear':2021,
    'ctl00$ContentPlaceHolder_content$uc_timeSelector$DropDownList_month_endMonth':1,
    'ctl00$ContentPlaceHolder_content$uc_productList_mixVer$CheckBoxList_priceType$0':1,
    'ctl00$ContentPlaceHolder_content$uc_productList_mixVer$CheckBoxList_productList_0_0$0':9,
    'ctl00$ContentPlaceHolder_content$uc_productList_mixVer$CheckBoxList_productList_0_0$2':15,
    'ctl00$ContentPlaceHolder_content$uc_productList_mixVer$CheckBoxList_productList_0_0$4':44011,
    'ctl00$ContentPlaceHolder_content$uc_productList_mixVer$CheckBoxList_productList_0_0$6':48090,
    'ctl00$ContentPlaceHolder_content$Button_query':'查詢'
}

url = 'http://price.naif.org.tw/Query/Query_now.aspx'

headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'}

resp = requests.post(url, data = payload)
soup = BeautifulSoup(resp.text, 'html.parser')

print(soup.find("table", {'id': 'ContentPlaceHolder_content_GridView_data'}))
0
uobik
iT邦新手 4 級 ‧ 2021-07-07 19:12:52

推個selenium

import time
from selenium import webdriver
from selenium.webdriver.support.select import Select

opt = webdriver.ChromeOptions()
opt.add_argument('--headless')  # 背景執行
driver = webdriver.Chrome(options=opt, executable_path='chromedriver.exe')  # path改成你的chromedriver.exe路徑

driver.get('http://price.naif.org.tw/Query/Query_now.aspx')
driver.find_element_by_id('ContentPlaceHolder_content_uc_timeSelector_RadioButton_month').click()
time.sleep(1)

startYear = driver.find_element_by_id('ContentPlaceHolder_content_uc_timeSelector_DropDownList_month_startYear')
selStartYear = Select(startYear)
selStartYear.select_by_value('2018')

startMonth = driver.find_element_by_id('ContentPlaceHolder_content_uc_timeSelector_DropDownList_month_startMonth')
selStartMonth = Select(startMonth)
selStartMonth.select_by_value('1')
time.sleep(1)

endYear = driver.find_element_by_id('ContentPlaceHolder_content_uc_timeSelector_DropDownList_month_endYear')
selEndYear = Select(endYear)
selEndYear.select_by_value('2019')

endMonth = driver.find_element_by_id('ContentPlaceHolder_content_uc_timeSelector_DropDownList_month_endMonth')
selEndMonth = Select(endMonth)
selEndMonth.select_by_value('10')
time.sleep(1)

driver.find_element_by_id('ContentPlaceHolder_content_uc_productList_mixVer_CheckBoxList_priceType_0').click()  # 產品農地價格
time.sleep(1)
driver.find_element_by_id('ContentPlaceHolder_content_uc_productList_mixVer_CheckBoxList_productList_1_0_8').click()  # 雞蛋
time.sleep(1)

driver.find_element_by_id('ContentPlaceHolder_content_Button_query').click()
time.sleep(2)

print(driver.page_source)
driver.quit()

https://ithelp.ithome.com.tw/upload/images/20210707/20138982vSYckNCsdW.png

0
blanksoul12
iT邦研究生 5 級 ‧ 2021-07-08 14:44:16

來個 excel vba

Sub get_egg()

With CreateObject("MSXML2.XMLHTTP.6.0")
    .Open "GET", "http://price.naif.org.tw/Query/Query_now.aspx", False '進入網頁
    .SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    .Send
    strText = .responsetext
    VIEWSTATE = encodeURI(CStr(Split(Split(strText, "__VIEWSTATE"" value=""")(1), """ />")(0))) 'VIEWSTATE
    VIEWSTATEGENERATOR = encodeURI(CStr(Split(Split(strText, "__VIEWSTATEGENERATOR"" value=""")(1), """ />")(0))) 'VIEWSTATEGENERATOR
    EVENTVALIDATION = encodeURI(CStr(Split(Split(strText, "__EVENTVALIDATION"" value=""")(1), """ />")(0))) 'EVENTVALIDATION
    
    .Open "POST", "http://price.naif.org.tw/Query/Query_now.aspx", False    '選產地農場價格
    .SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    msg = "__EVENTTARGET=ctl00%24ContentPlaceHolder_content%24uc_productList_mixVer%24CheckBoxList_priceType%240" '最尾的 0 = 產地農場價格, 1 = 市場拍賣價格, 2 = 零售價格
    msg = msg & "&__EVENTARGUMENT="
    msg = msg & "&__LASTFOCUS="
    msg = msg & "&__VIEWSTATE=" & VIEWSTATE
    msg = msg & "&__VIEWSTATEGENERATOR" & VIEWSTATEGENERATOR
    msg = msg & "&__SCROLLPOSITIONX=0"
    msg = msg & "&__SCROLLPOSITIONY=0"
    msg = msg & "&__EVENTVALIDATION=" & EVENTVALIDATION
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24RadioButtonList_resultType=0"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24time=RadionButton_year"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_startYear=1996"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_endYear=2021"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_month_startYear=2021"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_month_startMonth=1"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_month_endYear=2021"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_month_endMonth=1"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_productList_mixVer%24CheckBoxList_priceType%240=1" '如說其他,最的的 1 也要變的
    
    .Send msg
    strText = .responsetext
    CopyToClipbox (strText)
    
    VIEWSTATE = encodeURI(CStr(Split(Split(strText, "__VIEWSTATE"" value=""")(1), """ />")(0))) 'VIEWSTATE
    VIEWSTATEGENERATOR = encodeURI(CStr(Split(Split(strText, "__VIEWSTATEGENERATOR"" value=""")(1), """ />")(0))) 'VIEWSTATEGENERATOR
    EVENTVALIDATION = encodeURI(CStr(Split(Split(strText, "__EVENTVALIDATION"" value=""")(1), """ />")(0))) 'EVENTVALIDATION
    
    .Open "POST", "http://price.naif.org.tw/Query/Query_now.aspx", False '選家禽類 雞蛋
    .SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    msg = "__EVENTTARGET=ctl00%24ContentPlaceHolder_content%24uc_productList_mixVer%24CheckBoxList_productList_1_0%248" 'productList_1 的 1 = 家禽類, 0 = 家畜類, 2 = 飼料 / 最尾的 8 = 雞蛋, 0 = 白肉雞(活體), 6 = 鴨(番鴨)(活體)
    msg = msg & "&__EVENTARGUMENT="
    msg = msg & "&__LASTFOCUS="
    msg = msg & "&__VIEWSTATE=" & VIEWSTATE
    msg = msg & "&__VIEWSTATEGENERATOR=" & VIEWSTATEGENERATOR
    msg = msg & "&__SCROLLPOSITIONX=0"
    msg = msg & "&__SCROLLPOSITIONY=563"
    msg = msg & "&__EVENTVALIDATION=" & EVENTVALIDATION
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24RadioButtonList_resultType=0"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24time=RadionButton_year"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_startYear=2021"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_endYear=2021"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_month_startYear=2021"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_month_startMonth=1"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_month_endYear=2021"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_month_endMonth=1"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_productList_mixVer%24CheckBoxList_priceType%240=1"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_productList_mixVer%24CheckBoxList_productList_1_0%248=13" '如說其他,最尾的 productList_1_0%248=13 也要變的
    
    .Send msg
    strText = .responsetext
    CopyToClipbox (strText)
    VIEWSTATE = encodeURI(CStr(Split(Split(strText, "__VIEWSTATE"" value=""")(1), """ />")(0))) 'VIEWSTATE
    VIEWSTATEGENERATOR = encodeURI(CStr(Split(Split(strText, "__VIEWSTATEGENERATOR"" value=""")(1), """ />")(0))) 'VIEWSTATEGENERATOR
    EVENTVALIDATION = encodeURI(CStr(Split(Split(strText, "__EVENTVALIDATION"" value=""")(1), """ />")(0))) 'EVENTVALIDATION
    
    .Open "POST", "http://price.naif.org.tw/Query/Query_now.aspx", False '發出要求
    .SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    msg = "__EVENTTARGET="
    msg = msg & "&__EVENTARGUMENT="
    msg = msg & "&__LASTFOCUS="
    msg = msg & "&__VIEWSTATE=" & VIEWSTATE
    msg = msg & "&__VIEWSTATEGENERATOR=" & VIEWSTATEGENERATOR
    msg = msg & "&__SCROLLPOSITIONX=0"
    msg = msg & "&__SCROLLPOSITIONY=0"
    msg = msg & "&__EVENTVALIDATION=" & EVENTVALIDATION
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24RadioButtonList_resultType=0"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24time=RadionButton_year"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_startYear=1996"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_endYear=2021"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_month_startYear=2021"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_month_startMonth=1"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_month_endYear=2021"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_timeSelector%24DropDownList_month_endMonth=1"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_productList_mixVer%24CheckBoxList_priceType%240=1"
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24uc_productList_mixVer%24CheckBoxList_productList_1_0%248=13" '跟上面
    msg = msg & "&ctl00%24ContentPlaceHolder_content%24Button_query=%E6%9F%A5%E8%A9%A2"
    .Send msg
    strText = .responsetext
    CopyToClipbox (strText)
    Set temp_ie = CreateObject("htmlfile")
    temp_ie.Write .responsetext
    Set get_table = temp_ie.DocumentElement.all.tags("table")
    Set get_cell = get_table(get_table.Length - 1).Cells
    
    Cells.Clear
    For i = 4 To get_cell.Length - 1 Step 2
        [a1048576].End(xlUp).Offset(1, 0) = get_cell(i).innertext
        [a1048576].End(xlUp).Offset(0, 1) = get_cell(i + 1).innertext
    Next
End With
End Sub
Sub CopyToClipbox(strText As String)

   '文本拷?到剪?板

    With CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
        .SetText strText
        .PutInClipboard
    End With
End Sub
Function encodeURI(strText As String) As String
    With CreateObject("msscriptcontrol.scriptcontrol")
        .Language = "JavaScript"
        encodeURI = .Eval("encodeURIComponent('" & strText & "');")
    End With
End Function

我要發表回答

立即登入回答