Насколько я могу судить, я не создал список, но он дает мне
TypeError: Невозможно прочитать объект типа 'список'.
Есть мысли?
Python новичок, так что иди спокойно.
Любая и вся помощь приветствуется.
пример URL:
https://nclbgc.org/search/licenseDetails?licenseNumber=80479
вот полный возврат:
Traceback (most recent call last):
File "ncscribble.py", line 26, in <module>
df = pd.read_html(url)[0].dropna(how='all')
File "C:\Users\rkrouse\Desktop\Python\lib\site-packages\pandas\io\html.py", line 987, in read_html
displayed_only=displayed_only)
File "C:\Users\rkrouse\Desktop\Python\lib\site-packages\pandas\io\html.py", line 815, in _parse
raise_with_traceback(retained)
File "C:\Users\rkrouse\Desktop\Python\lib\site-packages\pandas\compat\__init__.py", line 404, in raise_with_traceback
raise exc.with_traceback(traceback)
TypeError: Cannot read object of type 'list'
Полный код:
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen
import time
import csv
import pandas as pd
import os
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
def license_exists(soup):
with open('NC_urls.csv','r') as csvf:
urls = csv.reader(csvf)
for url in urls:
if soup(class_='btn btn-primary"'):
return False
else:
return True
with open('NC_urls.csv','r') as csvf: # Open file in read mode
urls = csv.reader(csvf)
for url in urls:
df = pd.read_html(url)[0].dropna(how='all')
df = df.groupby(0)[1].apply(lambda x: ' '.join(x.dropna())).to_frame().rename_axis(None).T
if not license_exists(soup(page, 'html.parser')):
# if the license is present we don't want to parse any more urls.
break
df.to_csv('NC_Licenses_Daily.csv', index=False)