小编Gra*_*ant的帖子

为什么我无法通过POST返回到此jsf来获取数据

这是网站的URL:https ://dataviewer.pjm.com/dataviewer/pages/public/tieflows.jsf单击“ Tie Values”后,我要抓取的数据在弹出窗口中。

这是我的Python脚本:

import requests
from bs4 import BeautifulSoup

url = 'https://dataviewer.pjm.com/dataviewer/pages/public/tieflows.jsf'

data = {"javax.faces.partial.ajax": "true",
        "javax.faces.source": "chart1:j_idt293",
        "javax.faces.partial.execute": "@all",
        "javax.faces.partial.render": "chart1:valuesPanel",
        "chart1:j_idt293": "chart1:j_idt293",
        "chart1":"chart1",
        "chart1:selectedTie": "",
        "chart1:tieFlowState": "ACTUAL",
        "chart1:chart1tieflowDataTable_scrollState": "0,0"}

head = {}

with requests.Session() as s:
    init = s.get(url)
    soup = BeautifulSoup(init.text, "lxml")
    val = soup.find('input', {'id': 'javax.faces.ViewState'}).get('value')
    print(val)
    data["javax.faces.ViewState"] = val`enter code here`
    r = s.post(url, data=data, headers=head)
    print(r.text.strip())
Run Code Online (Sandbox Code Playgroud)

我得到了回应:

<?xml version="1.0" encoding="UTF-8"?>
<partial-response>
   <changes>
      <update id="formLeftPanel:dialogMessages"><![CDATA[<div id="formLeftPanel:dialogMessages" class="ui-messages ui-widget" aria-live="polite"></div>]]></update>
      <update id="globalMessages"><![CDATA[<div id="globalMessages" …
Run Code Online (Sandbox Code Playgroud)

python jsf beautifulsoup python-requests

5
推荐指数
0
解决办法
70
查看次数

标签 统计

beautifulsoup ×1

jsf ×1

python ×1

python-requests ×1