我正在尝试使用python下载动态网页,该网站是从脚本创建的。
不幸的是,网页下载时没有任何内容,不知道我做错了什么。
任何帮助将不胜感激
谢谢
代码是
import xlrd
import requests
import time
import sys
#----------------------------------------------------------------------
def open_file(path):
"""
Open and read an Excel file
"""
workbook = xlrd.open_workbook(path)
USERNAME = ""
PASSWORD = ""
sURLbase = "https://example.com/Orders/OrderDetail/"
sloginURL = "https://connect.example.com"
session = requests.session()
login_data = {
"action": "login",
"USERNAME" : "username",
"PASSWORD" : "password"
}
r = session.post(sloginURL, data=login_data)
print("Login Response: ", r)
time.sleep(5)
for s in workbook.sheets():
if s.name == "2014":
for row in range(s.nrows):
value = s.cell(row,5).value
if(value != ""):
if(value != "Order"):
try :
value = str(int(value))
except :
pass
sURL = (sURLbase + value)
print(sURL)
r = session.get(sURL)
while (r.status_code != 200):
print("Login")
r = session.get(sURL)
r = session.post(sloginURL, data=login_data)
print("Fetch Response: ", r)
sFileName = value + ".htm"
with open (sFileName, "w") as fh:
fh.writelines(r.text)
#----------------------------------------------------------------------
if __name__ == "__main__":
path = "C:\\Users\\name\\Desktop\\company\\company.xlsx"
open_file(path)strong text