Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何使用Python 3在此网页上提交此表单?_Python 3.x_Python Requests - Fatal编程技术网

Python 3.x 如何使用Python 3在此网页上提交此表单?

Python 3.x 如何使用Python 3在此网页上提交此表单?,python-3.x,python-requests,Python 3.x,Python Requests,简而言之,我对从网站下载搜索结果感兴趣,但我遇到了一个弹出窗口,要求输入。如何使用Python3(无Machanize)提交表单,以便获得搜索结果 本页: …具有以下格式: <div id="forcedVehicleQuestions" class="forcedUserInput" style="display: block; position: absolute; left: 50%; top: 40px; z-index: 6000; margin-left: -199px; ma

简而言之,我对从网站下载搜索结果感兴趣,但我遇到了一个弹出窗口,要求输入。如何使用Python3(无Machanize)提交表单,以便获得搜索结果

本页:

…具有以下格式:

<div id="forcedVehicleQuestions" class="forcedUserInput" style="display: block; position: absolute; left: 50%; top: 40px; z-index: 6000; margin-left: -199px; margin-top: 0px;">
        <div class="forcedContents clearfix">
            <a class="btn-remove" onclick="closeForced('Search','question');">
                <svg><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#shape-remove"></use></svg>
            </a>
            <form name="forcedQuestionsForm" id="forcedQuestionsForm">
                <h2 class="sans">
                    More Product Info Required
                </h2>
                <p id="questionText" class="questionText">
                    Brake Pads - Position
                </p>
                <div id="forceQuestionsRadio">

                        <div class="form-row">
                            <label class="questionRadio checkbox-radio" id="questionRadio" for="Front">
                                <input type="radio" id="Front" name="answer" value="10219">
                                Front
                            </label>
                        </div>

                        <div class="form-row">
                            <label class="questionRadio checkbox-radio" id="questionRadio" for="Rear">
                                <input type="radio" id="Rear" name="answer" value="10290">
                                Rear
                            </label>
                        </div>

                        <div class="form-row">
                            <label class="questionRadio checkbox-radio" id="questionRadio" for="Show all">
                                <input type="radio" id="Show all" checked="" name="answer" value="-1">
                                Show all
                            </label>
                        </div>

                </div>

                <input id="questionSubmit" type="button" class="btn btn-green btn-shadow" value="Continue" onclick="setQuestionAnswer('Brake Pads - Position',document.forms['forcedQuestionsForm'].elements['answer'],'Show all');">

                <div id="forcedVehicleQuestionsLoading" class="loading load-sm">
                    <div class="spinner"></div>
                </div>
            </form>
        </div>
    </div>

这段代码检索页面的HTML,但没有任何搜索结果。

这是js,我认为您必须使用selenium。可能我对它理解不够,但js不应该只通过提交HTML表单触发吗?或者JS正在进行提交?JS在浏览器上执行,
请求
只是将其作为文本读取。我推荐selenium,因为它运行js.ah,这很有意义。谢谢
#import HTTP libraries
import requests
#import HTML parsing libraries
import bs4

url = 'http://www.oreillyauto.com/site/c/search/Brake+Pads+&+Shoes/C0068/C0009.oap?model=G6&vi=1432754&year=2006&make=Pontiac'
answerURL = 'http://www.oreillyauto.com/site/ConditionSelectServlet?answer=-1'

print("Making request")
session = requests.Session()
session.headers.update({'referer': url})
r = session.get(answerURL)
print(r.status_code)

oreillyList = bs4.BeautifulSoup(r.text, "lxml")

print("Writing response...")
logfile = 'C:/Users/mhurley/Portable_Python/notebooks/' + output + '.log' 
with open(logfile, 'w') as file:
    file.write(oreillyList.prettify())
print("...done writing "+logfile)