如何使用Python导航到网页并下载在线报告? [英] How to navigate to a webpage and download an online report using Python?
问题描述
如何使用Python请求以下curl命令,请从Ads Manager(Facebook)下载报告?
How could you request the following curl command using Python please to download a report from Ads Manager (Facebook)?
curl "https://scontent-mad1-1.xx.fbcdn.net/v/t66.9516-6/reportid.csv/reportname.csv?_nc_cat=109^&_nc_sid=7a48f7^&_nc_ohc=m4lvbyCnNzsAX9VwD8m^&_nc_ad=z-m^&_nc_cid=0^&_nc_ht=scontent-mad1-1.xx^&oh=45e8967402708665322afdb82bad4a46^&oe=5F0D314B" ^
-H "authority: scontent-mad1-1.xx.fbcdn.net" ^
-H "upgrade-insecure-requests: 1" ^
-H "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36" ^
-H "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" ^
-H "sec-fetch-site: cross-site" ^
-H "sec-fetch-mode: navigate" ^
-H "sec-fetch-dest: iframe" ^
-H "referer: https://business.facebook.com/" ^
-H "accept-language: en-GB,en-US;q=0.9,en;q=0.8" ^
--compressed
您知道如何解决以下python请求以下载报告吗?
Do you know how to fix the following python request to download the report?
#!/usr/bin/env python3
import requests
url = "https://scontent-mad1-1.xx.fbcdn.net/v/t66.9516-6/<reportid.csv>/<reportname.csv>?_nc_cat=109^&_nc_sid=7a48f7^&_nc_ohc=m4lvbyCnNzsAX9VwD8m^&_nc_ad=z-m^&_nc_cid=0^&_nc_ht=scontent-mad1-1.xx^&oh=45e8967402708665322afdb82bad4a46^&oe=5F0D314B"
#headers to Python dictionary
headers = {"authority": "scontent-mad1-1.xx.fbcdn.net", "upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "sec-fetch-site": "cross-site", "sec-fetch-mode": "navigate", "sec-fetch-dest": "iframe", "referer": "https://business.facebook.com/", "accept-language": "en-GB,en-US;q=0.9,en;q=0.8"}
response = requests.get(url, headers=headers)
将报告下载到哪个文件夹中?
In which folder would the report be downloaded?
因为我需要登录Facebook才能下载,所以我需要输入Facebook用户名和密码吗?如果是这样,我该怎么办?
Do I need to enter the Facebook user and password since I need to be logged in Facebook to download it? And if so, how would I do that?
Facebook可以阻止我的帐户执行此请求吗?
Could Facebook block my account for executing this request?
感谢您的帮助.谢谢!
推荐答案
欢迎回来.每个 -H
都对应一个标题,因此,例如,您可以这样做:
Welcome back. Each -H
corresponds to a header, so for example, you would do:
#!/usr/bin/env python3
import requests
url = "https://scontent-mad1-1.xx.fbcdn.net/v/t66.9516-6/reportid.csv/reportname.csv?_nc_cat=109^&_nc_sid=7a48f7^&_nc_ohc=m4lvbyCnNzsAX9VwD8m^&_nc_ad=z-m^&_nc_cid=0^&_nc_ht=scontent-mad1-1.xx^&oh=45e8967402708665322afdb82bad4a46^&oe=5F0D314B"
# don't forget to add all the rest
headers = {"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"}
response = requests.get(url, headers=headers)
这篇关于如何使用Python导航到网页并下载在线报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!