我正在尝试将 URI 数组从我的 php 发送到我的 python 抓取工具。该数组包含要抓取的链接。
我从这里得到了示例,它可以很好地发送整数数组,但是当我尝试使用 URI 填充数组时,出现了错误。
php代码片段:
$array = ["https://www.google.com/","https://www.google.com/","https://www.google.com/"];
//$array = [1,2,3]; // This is worked fine
$resultScript= system('python C:\xampp\htdocs\selenium\dummy.py ' .escapeshellarg(json_encode($array)));
$resultData = json_decode($resultScript, true);
var_dump($resultData);
Python :
import sys
import json
def jsontoarray(json_data):
data = json.loads(json_data)
print(json.dumps(data))
jsontoarray(sys.argv[1])
print(data)
结果来自我的 IDE
Traceback (most recent call last):
File "C:\xampp\htdocs\selenium\dummy.py", line 8, in <module>
jsontoarray(sys.argv[1])
File "C:\xampp\htdocs\selenium\dummy.py", line 6, in jsontoarray
data = json.loads(json_data)
File "C:\Users\PC2\AppData\Local\Programs\Python\Python36-32\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\Users\PC2\AppData\Local\Programs\Python\Python36-32\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\PC2\AppData\Local\Programs\Python\Python36-32\lib\json\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 3 (char 2)
NULL
Process finished with exit code 0
holdtom
相关分类