【发布时间】:2014-05-12 09:59:52
【问题描述】:
这里有很多帮助,但其中一些超出了我的想象,所以希望通过提出我的问题并获得量身定制的答案,我会更好地理解。
到目前为止,我已成功连接到网站,以用户身份进行身份验证,填写表格,然后下拉 html。 html 包含我想要的表格。我只想说这样的话:-
读取 html... 当您读取表格开始标签时,请继续阅读表格结束标签,然后将其显示,或者将其写入新的 html 文件并打开它并保留标签,以便为我格式化。
这是我目前的代码。
# Use 'with' to ensure the session context is closed after use.
with requests.Session() as s:
s.post(LOGINURL, data=login)
# print
r = s.get(LOGINURL)
print r.url
# An authorised request.
r = s.get(APURL)
print r.url
# etc...
s.post(APURL)
#
r = s.post(APURL, data=findaps)
r = s.get(APURL)
#print r.text
f = open("makethisfile.html", "w")
f.write('\n'.join(['<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
'<html>',
' <head>',
' <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">',
' <title>THE TITLE</title>',
' <link rel="stylesheet" href="css/displayEventLists.css" type="text/css">',
r.text #this just does everything, i need to get the table.
])
)
f.close()
【问题讨论】:
-
你应该至少使用 HTMLParser docs.python.org/2/library/markup.html 或者甚至更强大的东西
-
谢谢,我现在去看看。
-
看看beautifulsoup stackoverflow.com/questions/17196018/…