我需要使用 Python 检索 JavaScript 文件内容。我认为也许 requests
可以解决问题 - 也许可以,但它要么不像我想象的那么简单,要么我做错了什么。
import requests
s = requests.Session()
r = s.get(link)
我得到的回复是
<HTML><HEAD>
<TITLE>Invalid URL</TITLE>
</HEAD><BODY>
<H1>Invalid URL</H1>
The requested URL "[no URL]", is invalid.<p>
Reference #9.3e1151c8.1484072058.308a223a
</BODY></HTML>
我需要的和这段代码在 php 中的作用是一样的,
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $link);
$html = curl_exec($ch);
最佳答案
您需要执行http get请求
import urllib2
link = "http://whatever.com/your-file.js"
urllib2.urlopen(link).read()
PHP 代码使用了curl,它的作用比看起来要多得多
关于javascript - 使用 Python 检索 javascript 文件内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41575695/