亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用動態 HTML (Python) 從網頁中抓取數據?

如何使用動態 HTML (Python) 從網頁中抓取數據?

炎炎設計 2023-05-25 17:26:12
我正在嘗試找出如何從以下網址抓取數據:https://www.aap.org/en-us/advocacy-and-policy/aap-health-initiatives/nicuverification/Pages/NICUSearch.aspx這是數據類型:似乎所有內容都是從數據庫中填充并通過 javascript 加載到網頁中的。我過去使用seleniumand做過類似的事情PhantomJS,但我不知道如何在 Python 中獲取這些數據字段。不出所料,我不能用于pd.read_html此類問題。是否可以解析以下結果:from selenium import webdriverurl="https://www.aap.org/en-us/advocacy-and-policy/aap-health-initiatives/nicuverification/Pages/NICUSearch.aspx"browser = webdriver.PhantomJS()browser.get(url)content = browser.page_source或者可能訪問實際的底層數據?如果沒有,除了幾個小時的復制和粘貼之外,還有什么其他方法?編輯:基于下面的答案,從@thenullptr 我已經能夠訪問材料但只能在第 1 頁上。我如何調整它以跨越所有頁面 [建議正確解析]?我的最終目標是將其放入熊貓數據框中import requestsfrom bs4 import BeautifulSoupr = requests.post(    url = 'https://search.aap.org/nicu/',     data = {'SearchCriteria.Level':'1', 'X-Requested-With':'XMLHttpRequest'}, ) #key:valuehtml = r.text# Parsing the HTML    soup = BeautifulSoup(html.split("</script>")[-1].strip(), "html")div = soup.find("div", {"id": "main"})div = soup.findAll("div", {"class":"blue-border panel list-group"})def f(x):    ignore_fields = ['Collapse all','Expand all']    output = list(filter(bool, map(str.strip, x.text.split("\n"))))    output = list(filter(lambda x: x not in ignore_fields, output))    return outputresults = pd.Series(list(map(f, div))[0])
查看完整描述

目前暫無任何回答

  • 0 回答
  • 0 關注
  • 109 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號