with open("proxies.txt","w+") as file:
[file.write(f"{p['ip']}:{p['port']}\n") for p in proxies]
В среде IDE не возникает проблем при работе, но при использовании PyInstaller (версия 7.1.2) она работает некоторое время, а затем выдает «Неверный синтаксис». Синтаксическая ошибка, в частности, относится ко второй строке (file.write).
Полный код (python 3)
import requests
from bs4 import BeautifulSoup
import os
print("Created by Shoutoutmymucas, 97% of the Code by Pured on")
parse_choice = input("HTML, Socks4 or Socks5?")
# capitilizes all the letters, idiot proof code
cap_ch = parse_choice.upper()
# debugging tool
print(cap_ch)
# core, will turn main part into def function when Socks5 and 4 features get added
if cap_ch == "HTML":
proxies = []
print("HTML Selected")
page = requests.get('https://free-proxy-list.net/')
soup = BeautifulSoup(page.text, 'html.parser')
text_table = soup.find('table', attrs={'id':'proxylisttable'})
body = text_table.find('tbody')
for row in body.find_all('tr'):
cols = row.find_all('td')[:7]
proxies.append({
'ip': cols[0].text,
'port': cols[1].text,
'iso': cols[2].text,
'country': cols[3].text,
'protocol': 'https' if cols[6].text == 'yes' else 'http',
'alive': True})
with open("proxies.txt","w+") as file:
[file.write(f"{p['ip']}:{p['port']}\n") for p in proxies]
os.startfile('proxies.txt')
else:
print("Socks4, Socks5 Not available yet. Contact ShoutOutMyMucas on if you want Socks4/5 in the next update.")
Ошибка, отображаемая в командной строке при попытке запустить на нем pyinstaller.
Syntax error in D:\Proxy Scarpe\scraper
File "D:\Proxy Scarpe\scraper", line 36
[file.write(f"{p['ip']}:{p['port']}\n") for p in proxies]
^
SyntaxError: invalid syntax