+++ 使用 Python 提交 [接受 - 按钮]
+++ Submit [ACCEPT - Button] with Python
我是 Python 的新手,对于可能出现的新手错误,请先接受我的歉意。我正在尝试解析 'simple' 网页:http://flow.gassco.no/
第一次在浏览器中打开页面时,我需要使用接受按钮确认 T&C。
我的解析工具是在Beautifulsoap中实现的,但是我无法解析内容。从 BS 打印 "response.text" 时,我得到以下代码。我如何绕过此表单以接受条款和条件?
这是我正在做的事情:
#!/usr/bin/env python
import requests
import bs4
index_url='http://flow.gassco.no/acceptDisclaimer'
def get_video_page_urls():
response = requests.get(index_url)
soup = bs4.BeautifulSoup(response.text)
return soup
print(get_video_page_urls())
谢谢!
<form action="acceptDisclaimer" method="get">
<input class="accept" type="submit" value="Accept"/>
<input class="decline" name="decline" onclick="window.location ='http://www.gassco.no'" type="button" value="Decline"/>
</form></div></div></div></div></div>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-30727768-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
您不需要解析该内容。您只需要向 http://flow.gassco.no/acceptDisclaimer
.
提出请求
此特定网站希望在您接受免责声明时按原样发送在它提供主页 (http://flow.gassco.no
) 时发送给用户代理的 cookie。因此,您可以通过发出两个请求来使您的脚本工作:一个用于主页,一个用于接受免责声明。为此,以下代码片段完成了获取主页的工作:
url1 = 'http://flow.gassco.no/'
res1 = requests.get(url1)
url2 = 'http://flow.gassco.no/acceptDisclaimer/'
res2 = requests.get(url2, cookies=res1.cookies)
print(res2.text) # The actual home page
我是 Python 的新手,对于可能出现的新手错误,请先接受我的歉意。我正在尝试解析 'simple' 网页:http://flow.gassco.no/
第一次在浏览器中打开页面时,我需要使用接受按钮确认 T&C。
我的解析工具是在Beautifulsoap中实现的,但是我无法解析内容。从 BS 打印 "response.text" 时,我得到以下代码。我如何绕过此表单以接受条款和条件?
这是我正在做的事情:
#!/usr/bin/env python
import requests
import bs4
index_url='http://flow.gassco.no/acceptDisclaimer'
def get_video_page_urls():
response = requests.get(index_url)
soup = bs4.BeautifulSoup(response.text)
return soup
print(get_video_page_urls())
谢谢!
<form action="acceptDisclaimer" method="get">
<input class="accept" type="submit" value="Accept"/>
<input class="decline" name="decline" onclick="window.location ='http://www.gassco.no'" type="button" value="Decline"/>
</form></div></div></div></div></div>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-30727768-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
您不需要解析该内容。您只需要向 http://flow.gassco.no/acceptDisclaimer
.
此特定网站希望在您接受免责声明时按原样发送在它提供主页 (http://flow.gassco.no
) 时发送给用户代理的 cookie。因此,您可以通过发出两个请求来使您的脚本工作:一个用于主页,一个用于接受免责声明。为此,以下代码片段完成了获取主页的工作:
url1 = 'http://flow.gassco.no/'
res1 = requests.get(url1)
url2 = 'http://flow.gassco.no/acceptDisclaimer/'
res2 = requests.get(url2, cookies=res1.cookies)
print(res2.text) # The actual home page