在python3中,我编写了一个程序,用于在多个页面上刮取表行的内容(97893)。每一页都有一组表,所以我浏览每一页并填写一个列表
from bs4 import BeautifulSoup
import requests
def sopa(link):
res = requests.get(link)
soup = BeautifulSoup(res.text, "lxml")
table = soup.select("table")[1]
conjunto = table.findAll("tr")
return conjunto
planilha = []
for i in range(1,97893):
link = "http://www.portaltransparencia.gov.br/PortalComprasDiretasFavorecido.asp?TipoPesquisa=2&Ano=2017&Pagina="
link = link + str(i)
conjunto = sopa(link)
conta = 0
for linha in conjunto:
if conta > 0:
documento = linha.find("td", {"class": "firstChild"}, {"style": "white-space: nowrap;"}).text.strip()
nome = linha.find("a").text.strip()
valor = linha.find("td", {"class": "colunaValor"}).text.strip()
dicionario = {"documento": documento, "nome": nome, "valor": valor}
planilha.append(dicionario)
conta = conta + 1
但在第458页出现了这样的错误:
^{pr2}$我相信我被推翻是因为我按顺序访问了许多页面。拜托,有人知道我该怎么避免吗?在
目前没有回答
相关问题 更多 >
编程相关推荐