【问题标题】:Read lines from GitHub user content file从 GitHub 用户内容文件中读取行
【发布时间】:2020-02-11 02:57:36
【问题描述】:

我正在尝试从 GitHub 用户内容中读取文本文件(代理列表)。代码将返回一个随机行,但它没有按预期工作。

我的代码:

res = reqs.get('https://raw.githubusercontent.com/clarketm/proxy-list/master/proxy-list-raw.txt', headers={'User-Agent':'Mozilla/5.0'})
proxies = []
for lines in res.text:
    proxies = ''.join(lines)
    print proxies
return proxies

这是我得到的:

.
2
1
:
8
0
8
0


1
9
2
.
1
6
2
.
6
2
.
1
9
7
:
5
9
2
4
6

这是预期的:

178.217.106.245:8080
186.192.98.250:8080

如果可以返回随机行那就更好了。

【问题讨论】:

  • 更改了标题以跟随内容,改进了帖子的格式,包括代码部分和文本。

标签: python python-2.7 proxy python-requests


【解决方案1】:

结果是一个字符串,遍历字符串是遍历字母,而不是行。
您必须用换行符拆分字符串并对其进行迭代:

for lines in res.text.split('\n'):
   ...

【讨论】:

    猜你喜欢
    • 2020-08-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-19
    • 2020-09-18
    • 2017-08-13
    • 2022-01-05
    • 2012-01-29
    • 1970-01-01
    相关资源
    最近更新 更多