因此,我正在做一个易受攻击的站点检查程序,并使用类进行了此操作。我有一类用于修复代理,另一类用于检查代理。现在,我已经完成了代理类,并从检查文件开始了,但是出现错误。
class proxy:
def __init__(self):
self.hdr = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate',
'DNT': '1',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1'}
def getrandproxy(self):
proxies = []
r = requests.get("https://free-proxy-list.net/anonymous-proxy.html", headers=self.hdr)
soup = BS(r.text, "lxml")
container = soup.find("body").section.div.find('div', ['table-responsive']).table.tbody #path from body to proxy table, since parsing directly to it doesn't work
for tr in container.find_all("tr"):
ip = tr.td.text
port = tr.td.next_sibling.text
anonimity = tr.td.next_sibling.next_sibling.next_sibling.next_sibling.text
https = tr.td.next_sibling.next_sibling.next_sibling.next_sibling.next_sibling.next_sibling.text
if https == "yes" and anonimity == "anonymous" or anonimity == "elite proxy":
server = ip + ":" + port
proxies.append(server)
return proxies
import requests, proxy
abc = proxy.getrandproxy()
print(abc)
我尝试自行打印模块,并且它可以正常工作。我只是似乎无法弄清楚为什么会有错误。我从proxy.py中删除了一些代码,因为这会很长。告诉我是否需要所有代码。顺便说一句,我剪切的代码不是必需的,只是带有其他功能的一些代码。
Traceback (most recent call last): File "injection.py", line 2, in <module> abc = proxy.getrandproxy()
AttributeError: module 'proxy' has no attribute 'getrandproxy'
答案 0 :(得分:0)
import requests, proxy
abc = proxy.proxy().getrandproxy()
print(abc)
您有一个名为proxy
的模块,该模块内有一个名为proxy
的类