我运行代码很好,然后我调整代码并保存并关闭它,试图再次运行它并得到语法错误。我愚蠢的自己没有备份原始代码,现在我所做的任何更改似乎都无法修复它。我检查了网站的源代码,并没有改变。甚至在检查网站之前就出错了。关于我忽略的任何建议?import requestsimport timeimport bs4import syssys.stdout = open("links2.txt", "a")for x in range(0, 100000): try: URL = f'https://wesbite.com/{x}' page = requests.get(URL) time.sleep(1) soup = BeautifulSoup(page.content, 'html.parser') website = "https://v.website.com/" for links in soup.find('div',id='view').find_all('a'): parts = links['href'].split("/") new_link = parts[1].replace(parts[1], website) + '/'.join(parts[2:]) + ".mp4" print(new_link) except: continue它在以下行报告语法错误:URL = f'https://wesbite.com/{x}'
1 回答
ibeautiful
TA贡献1993条经验 获得超5个赞
现在这是您的工作代码:
import requests
import time
from bs4 import BeautifulSoup
import sys
sys.stdout = open("links2.txt", "a")
for x in range(0, 100000):
try:
URL = f'https://wesbite.com/{x}'
page = requests.get(URL)
time.sleep(1)
soup = BeautifulSoup(page.content, 'html.parser')
website = "https://v.website.com/"
for links in soup.find('div',id='view').find_all('a'):
parts = links['href'].split("/")
new_link = parts[1].replace(parts[1], website) + '/'.join(parts[2:]) + ".mp4"
print(new_link)
except:
continue
它是:
import bs4
现在:
from bs4 import BeautifulSoup
添加回答
举报
0/150
提交
取消