#爬取部分
#一:对有标签的内容进行爬取
#打开文件
out=open(‘d:/分表.csv’,‘w’,newline=’\n’,encoding=‘gb18030’)
csv_write=csv.writer(out,dialect=‘excel’)
#数据爬取
for page in range (1,285):
略
xpath1=’//*[@id=“problemset”]/tbody’
driver.get(url1)
table1=driver.find_element_by_xpath(xpath1).get_attribute(‘innerHTML’)
soup=BeautifulSoup(table1,‘html.parser’)
table=soup.find_all(‘tr’)
for row in table:
cols=[col.text for col in row.find_all('td')]
if len(cols[3])==1:
continue
if len(cols[3])>3:
continue
cols[6]=page
print(cols[1:7])
csv_write.writerow(cols[1:7])
out.close()
#二:对所有内容进行爬取
#打开文件
out=open(‘d:/总表.csv’,‘w’,newline=’\n’,encoding=‘gb18030’)
csv_write=csv.writer(out,dialect=‘excel’)
#数据爬取
for page in range (1,285):
略
xpath1