import urllib.request
import csv
import http.client
import bs4
import Data
import re
from bs4 import BeautifulSoup
from Data import DA
#Extracting Html code from the URL
with urllib.request.urlopen("http://www.apecbraking.co.uk/catalogue/frictionParts/range/783854") as url:
D = url.read()
#HTML Code *
soup = BeautifulSoup(D)
Table = (soup.table)
soup = (Table.get_text())
#Creates 'APEC.csv'
file = open("APEC.csv", "w")
file.write(soup)
file.close()
print('Written')
# Set the Data into a list so it can be refered back to later on e.g searching for only words with certain letter
# from there they can be seperated from one list into categories (Variables)
newRow = []
with open('APEC.csv') as f:
reader = csv.reader(f)
for row in reader:
print()
#New List
newRow.append(row)
print(re.findall('A'))
Anyone explain to me whats wrong i do not understand tbh :/
Error
Traceback (most recent call last): File "C:/Users/B8/Desktop/Task/TaskOriginal.py", line 49, in <module> print(newRow.findall('A')) AttributeError: 'list' object has no attribute 'findall'
Ignore had to add more detail to update sdfdsffffffffffffffffffffddfsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
try using
with open('yourfile') as f:
new_list = [row for row in f if row.startswith('A')]
Your newRow
has type list
. That has no method associated with this type. You can get list of all available methods for this type by typing help(list)
in python console.
You need to import the regular expression library
import re
OR just try this snippet of code
print([item for item in newRow if item[0]=='A'])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.