Github上不去登不了的解決辦法
(1)雙擊小工具找到可以用的 ip(下圖中success_hosts部分就是可用ip)
直接上小工具,雙擊即可執行
:
連結:
https://
pan。baidu。com/s/1r0CMXt
5rsTe3nV9JK8blnA
提取碼:8x8u
(2)修改 hosts 檔案:
hosts檔案所在位置:Windows 系統位於 C:\Windows\System32\drivers\etc\
(3)在cmd視窗中輸入: ipconfig /flushdns 命令更新
附上小工具原始碼
import re
import time
import requests
from selenium import webdriver
from bs4 import BeautifulSoup
class GetIP(object):
def __init__(self, driver_path=‘E:\\test\\chromedriver。exe’):
“”“
driver_path:the path of the chrome driver, which is downloaded from http://chromedriver。storage。googleapis。com/index。html
note the version should be corresponding between chrome driver and chrome webbrowser
”“”
self。path = driver_path
self。urls = [
“https://github。com。ipaddress。com/www。github。com”,
“https://github。com。ipaddress。com/”, #github。com
“https://github。com。ipaddress。com/gist。github。com”,
“https://githubusercontent。com。ipaddress。com/gist。githubusercontent。com”,
“https://githubusercontent。com。ipaddress。com/raw。githubusercontent。com”,
“https://github。com。ipaddress。com/assets-cdn。github。com”,
“https://githubusercontent。com。ipaddress。com/cloud。githubusercontent。com”,
“https://githubusercontent。com。ipaddress。com/camo。githubusercontent。com”,
“https://githubusercontent。com。ipaddress。com/avatars0。githubusercontent。com”,
“https://githubusercontent。com。ipaddress。com/avatars1。githubusercontent。com”,
“https://githubusercontent。com。ipaddress。com/avatars2。githubusercontent。com”,
“https://githubusercontent。com。ipaddress。com/avatars3。githubusercontent。com”,
“https://githubusercontent。com。ipaddress。com/avatars4。githubusercontent。com”,
“https://githubusercontent。com。ipaddress。com/avatars5。githubusercontent。com”,
“https://githubusercontent。com。ipaddress。com/avatars6。githubusercontent。com”,
“https://githubusercontent。com。ipaddress。com/avatars7。githubusercontent。com”,
“https://githubusercontent。com。ipaddress。com/avatars8。githubusercontent。com”,
]
def getip_req(self, url):
“”“
use request to get the ip of github (better and faster)
url: the url which ip you want to search
”“”
response = requests。get(url) # 部分網站可用
status = response。status_code
# print(status)
# print (response。headers[‘content-type’])
soup = BeautifulSoup(response。content,“html。parser”) # ,from_encoding=“utf-8”)
link_node = soup。find(‘a’,href=re。compile(r“ipv4”))
ip = link_node。get_text() if status == 200 else None # success 200, fail 404
return ip
def getip_sel(self, url):
“”“
use selenium to get the ip of github
url: the url which ip you want to search
”“”
self。driver = webdriver。Chrome(executable_path=self。path)
self。driver。get(‘https://github。com。ipaddress。com’)
self。driver。implicitly_wait(7)
inputElement = self。driver。find_elements_by_name(‘host’)
searchButton = self。driver。find_elements_by_class_name(‘search’)
inputElement[0]。send_keys(url) # search url in search box
searchButton[0]。click() # click the corresponding button
browser_res = self。driver。page_source
# print(browser_res)
soup = BeautifulSoup(browser_res,“html。parser”) # ,from_encoding=“utf-8”)
link_node = soup。find(‘a’,href=re。compile(r“ipv4”))
# print (link_node。name,link_node[‘href’],link_node。get_text())
return link_node。get_text() if link_node != None else None # get the ip of the url
def github_hosts(self, get_type=0):
“”“
get_type: the way we use to get ip, get_type=0:request(default) | get_type=1:selenium
”“”
success_hosts = {}
failure_hosts = {}
for url in self。urls:
host_url = url。strip()。split(‘/’)[-1]
host_url = host_url if host_url != ‘’ else ‘github。com’
try:
# print(host)
ip = self。getip_req(url) if get_type==0 else self。getip_sel(host_url)
print(ip, host_url)
if ip == None:
failure_hosts[host_url] = ip # sometimes different host has the same ip
else:
success_hosts[host_url] = ip
if get_type == 1:
time。sleep(0。7)
self。driver。quit()
except Exception as err:
failure_hosts[host_url] = None
print(err)
print(‘————————————————————————’)
print(‘faiure_hosts:\n’, failure_hosts)
print(‘————————————————————————’)
print(‘success_hosts:’)
for k, v in success_hosts。items():
print(v, k)
print(‘————————————————————————’)
if __name__ == ‘__main__’:
ip_obj = GetIP()
ip_obj。github_hosts(get_type=0)
參考內容及程式碼來源