代码:
import requests
file = open("test.txt")
for url in file:
response = requests.get(url)
print(response.status_code)
--------- test.txt -----------
https://www.google.com
O / p在终端:
404
当我在空闲状态下使用它时:
Python 3.6.8 (default, Oct 7 2019, 12:59:55)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> response = requests.get("https://google.com")
>>> response.status_code
200
答案 0 :(得分:1)
文件中的每个url
的末尾都有换行符。尝试strip()
添加它:
for url in file:
response = requests.get(url.strip())
答案 1 :(得分:0)
您忽略了一个简单的部分。只需在
public class LineUp {
Act[] acts;
public LineUp() {
Act[] acts = new Act[30];
}
void addAct(Act a) {
}
}
之后添加.readlines()
。我的意思是:
file
这对我有用。希望对您有所帮助:)