github国内

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/YongYu_IT/article/details/56686189

1、假设python安装目录是E:\Python34

2、在E:\Python34下新建test文件夹

3、E:\Python34\test下创建github.py如下:

import requests
from bs4 import BeautifulSoup

for i in open("./test/haha.txt"):
    url = "http://ip.chinaz.com/" + i.strip()
    resp = requests.get(url)
    soup=BeautifulSoup(resp.text)
    x=soup.find(class_="IcpMain02")
    x=x.find_all("span",class_="Whwtdhalf")
    print(x[5].string.strip(),i.strip())
在E:\Python34\test下创建haha.txt如下:

github.com
assets-cdn.github.com
avatars0.githubusercontent.com
avatars1.githubusercontent.com
documentcloud.github.com
gist.github.com
help.github.com
nodeload.github.com
raw.github.com
status.github.com
training.github.com
github.io

4、执行

E:\Python34>python ./test/github.py

如果提示ImportError: No module named 'requests'

执行 E:\Python34\Scripts>pip install requests

其他ImportError: No module named 'XXX'错误也类似

最终输出

192.30.253.112 github.com
151.101.100.133 assets-cdn.github.com
151.101.100.133 avatars0.githubusercontent.com
151.101.100.133 avatars1.githubusercontent.com
151.101.100.133 documentcloud.github.com
203.98.7.65 gist.github.com
151.101.100.133 help.github.com
192.30.253.121 nodeload.github.com
151.101.100.133 raw.github.com
50.16.213.254 status.github.com
151.101.100.133 training.github.com
23.235.37.133 github.io

5、将上述输出粘贴到C:\Windows\System32\drivers\etc\hosts重启

展开阅读全文

没有更多推荐了,返回首页