跳到正文

剪贴板

剪贴板 nc37thdo

原文
剪贴板信息

剪贴板信息

收录
更新

需要依赖requests、bs4、lxml库。

Python
file=open("results.txt","x")
file1=open("error.txt","x")
from bs4 import BeautifulSoup
import requests
url="https://nh.51goc.com/problemVideoNoteOpen/videConfirmform?studentId="
url1="&problemId=888"
i=0
err=0
while 1:
    i=i+1
    try:
        response = requests.get(url+str(i)+url1)
        response.encoding = 'utf-8'
        soup = BeautifulSoup(response.text, 'lxml')
        all_links = soup.find_all('h3')
        print('crawing',i,'\n')
        if len(all_links)==0:
            err=err+1
            if err>=250:
                break
            continue
        err=0
        text=str(all_links[0])
        x = text.find("您的小孩")
        y = text.find(",想观看题目为哪个大?")
        file.write(str(i)+':')
        file.write(text[x+4:y])
        file.write('\n')
    except UnicodeEncodeError:
        file1.write("error on "+str(i)+'\n')