Python 代理请求无法执行
我正在试验代理服务器,我想创建一个机器人,每隔几分钟连接一次我的web服务器,并刮取一个文件(即index.html)进行更改 我试着应用我在几个小时的python教程中学到的东西,结果使它变得更有趣,我可以使用随机代理 所以我写下了这个方法:Python 代理请求无法执行,python,web,proxy,request,Python,Web,Proxy,Request,我正在试验代理服务器,我想创建一个机器人,每隔几分钟连接一次我的web服务器,并刮取一个文件(即index.html)进行更改 我试着应用我在几个小时的python教程中学到的东西,结果使它变得更有趣,我可以使用随机代理 所以我写下了这个方法: import requests from bs4 import BeautifulSoup from random import choice #here I get the proxy from a proxylist due processing
import requests
from bs4 import BeautifulSoup
from random import choice
#here I get the proxy from a proxylist due processing a table embedded in html with beautifulSoup
def get_proxy():
print("bin in get_proxy")
proxyDomain = 'https://free-proxy-list.net/'
r = requests.get(proxyDomain)
print("bin in mache gerade suppe")
soup = BeautifulSoup(r.content, 'html.parser')
table = soup.find('table', {'id': 'proxylisttable'})
#this part works
#print(table.get_text)
print("zeit für die Liste")
ipAddresses = []
for row in table.findAll('tr'):
columns = row.findAll('td')
try:
ipAddresses.append("https://"+str(columns[0].get_text()) + ":" + str(columns[1].get_text()))
#ipList.append(str(columns[0].get_text()) + ":" + str(columns[1].get_text()))
except:
pass
#here the program returns one random IP Address from the list
return choice(ipAddresses)
# return 'https://': + choice(iplist)
def proxy_request(request_type, url, **kwargs):
print("bin in proxy_request")
while 1:
try:
proxy = get_proxy()
print("heute verwenden wir {}".format(proxy))
#so until this line everything seems to work as i want it to do
#now the next line should do the proxied request and at the end of the loop it should return some html text....
r = requests.request(request_type, url, proxies=proxy, timeout=5, **kwargs)
break
except:
pass
return r
def launch():
print("bin in launch")
r = proxy_request('get', 'https://mysliwje.uber.space.')
### but this text never arrives here - maybe the request is going to be carried out the wrong way
###does anybody got a idea how to solve that program so that it may work?
print(r.text)
launch()
正如我在前面的代码部分中所解释的,该代码运行良好,它从随机ip列表中选择一些随机ip,甚至将其打印到cli。下一步似乎突然以错误的方式执行,因为这些工具正在运行,以获取一个新的ip地址
还有一个
还有一个
还有一个
还有一个。。。
似乎每隔几分钟就会更新一次的列表。。。。
所以我问自己发生了什么,为什么我看不到我的InExpage的简单html代码
有人知道吗
Thanxx您的代码是否一直处于循环中?while 1:while在打印出拟合结果后得到休息,正如break语句所暗示的那样,嘿,我又坐在我的程序上,随着时间的推移,有人修复了我的拼写错误,但我不明白,我的程序中到底有什么东西把输出搞乱了:/you’请帮助我好吗