Issue
I had this at one point and it was very simple but I can't get it back to how it was. I had a list of lists that contained each selected attr for each corresponding html tag. Code:
import requests
import pandas as pd
from bs4 import BeautifulSoup
# get link and parse
page = requests.get('https://www.finviz.com/screener.ashx?v=111&ft=4')
soup = BeautifulSoup(page.text, 'html.parser')
filters = soup.find_all('select', attrs={'data-filter': True})
filter_list = []
for f in filters:
filter_list.append(f.get('data-filter'))
option = soup.find_all('option', attrs={'value': True})
option_list = []
for f in filters:
# this is the line I lost that gathered the list of strings from the list of html tags
# what I currently have builds a list of lists but the lists are empty:
option_list.append(f.find_all('value'))
print(option_list)
Sample html:
# I want a list for each of these in filters
<select id="fs_exch" style="width: 100%; visibility: visible;" class="screener-combo-text" onmouseover="IESelectExpand(this);" onblur="IESelectShrink(this);" onchange="ScreenerSelectOnChange(this)" data-filter="exch" data-url="v=111&ft=4" data-url-selected="v=111&f=exch_selected_filter&ft=4" data-selected="">
# i want to put the following into a list
<option selected="selected" value="">Any</option>
<option value="amex">AMEX</option>
<option value="nyse">NYSE</option>
<option value="nasd">NASDAQ</option>
<option value="modal">Custom (Elite only)</option>
Desired output:
[[...], [...], ['', 'amex', 'nyse', 'nasd'], ..., [...]]
I'm either getting back empty lists or the datatypes with my recent attempts. It doesn't
Solution
Try the following css selector to get the value in list.
page = requests.get('https://www.finviz.com/screener.ashx?v=111&ft=4')
soup = BeautifulSoup(page.text, 'html.parser')
finallist=[]
for items in soup.select("select[data-filter]"):
lista=[item['value'] for item in items.select("option[value]") if item['value']!='']
finallist.append(lista)
print(finallist)
[['amex', 'nasd', 'nyse', 'modal'], ['sp500', 'dji'], ['basicmaterials', 'conglomerates', 'consumergoods', 'financial', 'healthcare', 'industrialgoods', 'services', 'technology', 'utilities', 'modal'], ['stocksonly', 'exchangetradedfund', 'accidenthealthinsurance', 'advertisingagencies', 'aerospacedefensemajordiversified', 'aerospacedefenseproductsservices', 'agriculturalchemicals', 'airdeliveryfreightservices', 'airservicesother', 'aluminum', 'apparelstores', 'appliances', 'applicationsoftware', 'assetmanagement', 'autodealerships', 'automanufacturersmajor', 'autoparts', 'autopartsstores', 'autopartswholesale', 'basicmaterialswholesale', 'beveragesbrewers', 'beveragessoftdrinks', 'beverageswineriesdistillers', 'biotechnology', 'broadcastingradio', 'broadcastingtv', 'buildingmaterialswholesale', 'businessequipment', 'businessservices', 'businesssoftwareservices', 'catalogmailorderhouses', 'catvsystems', 'cement', 'chemicalsmajordiversified', 'cigarettes', 'cleaningproducts', 'closedendfunddebt', 'closedendfundequity', 'closedendfundforeign', 'communicationequipment', 'computerbasedsystems', 'computerperipherals', 'computerswholesale', 'confectioners', 'conglomerates', 'consumerservices', 'copper', 'creditservices', 'dairyproducts', 'datastoragedevices', 'departmentstores', 'diagnosticsubstances', 'discountvarietystores', 'diversifiedcommunicationservices', 'diversifiedcomputersystems', 'diversifiedelectronics', 'diversifiedinvestments', 'diversifiedmachinery', 'diversifiedutilities', 'drugdelivery', 'drugmanufacturersmajor', 'drugmanufacturersother', 'drugrelatedproducts', 'drugsgeneric', 'drugstores', 'drugswholesale', 'educationtrainingservices', 'electricutilities', 'electronicequipment', 'electronicsstores', 'electronicswholesale', 'entertainmentdiversified', 'farmconstructionmachinery', 'farmproducts', 'foodmajordiversified', 'foodwholesale', 'foreignmoneycenterbanks', 'foreignregionalbanks', 'foreignutilities', 'gamingactivities', 'gasutilities', 'generalbuildingmaterials', 'generalcontractors', 'generalentertainment', 'gold', 'grocerystores', 'healthcareinformationservices', 'healthcareplans', 'heavyconstruction', 'homefurnishingsfixtures', 'homefurnishingstores', 'homehealthcare', 'homeimprovementstores', 'hospitals', 'housewaresaccessories', 'independentoilgas', 'industrialelectricalequipment', 'industrialequipmentcomponents', 'industrialequipmentwholesale', 'industrialmetalsminerals', 'informationdeliveryservices', 'informationtechnologyservices', 'insurancebrokers', 'internetinformationproviders', 'internetserviceproviders', 'internetsoftwareservices', 'investmentbrokeragenational', 'investmentbrokerageregional', 'jewelrystores', 'lifeinsurance', 'lodging', 'longdistancecarriers', 'longtermcarefacilities', 'lumberwoodproduction', 'machinetoolsaccessories', 'majorairlines', 'majorintegratedoilgas', 'managementservices', 'manufacturedhousing', 'marketingservices', 'meatproducts', 'medicalappliancesequipment', 'medicalequipmentwholesale', 'medicalinstrumentssupplies', 'medicallaboratoriesresearch', 'medicalpractitioners', 'metalfabrication', 'moneycenterbanks', 'mortgageinvestment', 'movieproductiontheaters', 'multimediagraphicssoftware', 'musicvideostores', 'networkingcommunicationdevices', 'nonmetallicmineralmining', 'officesupplies', 'oilgasdrillingexploration', 'oilgasequipmentservices', 'oilgaspipelines', 'oilgasrefiningmarketing', 'packagingcontainers', 'paperpaperproducts', 'personalcomputers', 'personalproducts', 'personalservices', 'photographicequipmentsupplies', 'pollutiontreatmentcontrols', 'printedcircuitboards', 'processedpackagedgoods', 'processingsystemsproducts', 'propertycasualtyinsurance', 'propertymanagement', 'publishingbooks', 'publishingnewspapers', 'publishingperiodicals', 'railroads', 'realestatedevelopment', 'recreationalgoodsother', 'recreationalvehicles', 'regionalairlines', 'regionalmidatlanticbanks', 'regionalmidwestbanks', 'regionalnortheastbanks', 'regionalpacificbanks', 'regionalsoutheastbanks', 'regionalsouthwestbanks', 'reitdiversified', 'reithealthcarefacilities', 'reithotelmotel', 'reitindustrial', 'reitoffice', 'reitresidential', 'reitretail', 'rentalleasingservices', 'researchservices', 'residentialconstruction', 'resortscasinos', 'restaurants', 'rubberplastics', 'savingsloans', 'scientifictechnicalinstruments', 'securityprotectionservices', 'securitysoftwareservices', 'semiconductorbroadline', 'semiconductorequipmentmaterials', 'semiconductorintegratedcircuits', 'semiconductormemorychips', 'semiconductorspecialized', 'shipping', 'silver', 'smalltoolsaccessories', 'specializedhealthservices', 'specialtychemicals', 'specialtyeateries', 'specialtyretailother', 'sportingactivities', 'sportinggoods', 'sportinggoodsstores', 'staffingoutsourcingservices', 'steeliron', 'suretytitleinsurance', 'synthetics', 'technicalservices', 'technicalsystemsoftware', 'telecomservicesdomestic', 'telecomservicesforeign', 'textileapparelclothing', 'textileapparelfootwearaccessories', 'textileindustrial', 'tobaccoproductsother', 'toyhobbystores', 'toysgames', 'trucking', 'trucksothervehicles', 'wastemanagement', 'waterutilities', 'wholesaleother', 'wirelesscommunications', 'modal'], ['usa', 'notusa', 'asia', 'europe', 'latinamerica', 'bric', 'argentina', 'australia', 'bahamas', 'belgium', 'benelux', 'bermuda', 'brazil', 'britishvirginislands', 'canada', 'caymanislands', 'channelislands', 'chile', 'china', 'chinahongkong', 'colombia', 'cyprus', 'denmark', 'finland', 'france', 'germany', 'greece', 'hongkong', 'hungary', 'iceland', 'india', 'indonesia', 'ireland', 'israel', 'italy', 'japan', 'kazakhstan', 'luxembourg', 'malaysia', 'marshallislands', 'mexico', 'monaco', 'netherlands', 'netherlandsantilles', 'newzealand', 'norway', 'panama', 'papuanewguinea', 'peru', 'philippines', 'portugal', 'russia', 'singapore', 'southafrica', 'southkorea', 'spain', 'sweden', 'switzerland', 'taiwan', 'turkey', 'unitedarabemirates', 'unitedkingdom', 'modal'], ['mega', 'large', 'mid', 'small', 'micro', 'nano', 'largeover', 'midover', 'smallover', 'microover', 'largeunder', 'midunder', 'smallunder', 'microunder', 'frange'], ['low', 'profitable', 'high', 'u5', 'u10', 'u15', 'u20', 'u25', 'u30', 'u35', 'u40', 'u45', 'u50', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'o35', 'o40', 'o45', 'o50', 'range'], ['low', 'profitable', 'high', 'u5', 'u10', 'u15', 'u20', 'u25', 'u30', 'u35', 'u40', 'u45', 'u50', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'o35', 'o40', 'o45', 'o50', 'range'], ['low', 'high', 'u1', 'u2', 'u3', 'o1', 'o2', 'o3', 'range'], ['low', 'high', 'u1', 'u2', 'u3', 'u4', 'u5', 'u6', 'u7', 'u8', 'u9', 'u10', 'o1', 'o2', 'o3', 'o4', 'o5', 'o6', 'o7', 'o8', 'o9', 'o10', 'range'], ['low', 'high', 'u1', 'u2', 'u3', 'u4', 'u5', 'u6', 'u7', 'u8', 'u9', 'u10', 'o1', 'o2', 'o3', 'o4', 'o5', 'o6', 'o7', 'o8', 'o9', 'o10', 'range'], ['low', 'high', 'u1', 'u2', 'u3', 'u4', 'u5', 'u6', 'u7', 'u8', 'u9', 'u10', 'o1', 'o2', 'o3', 'o4', 'o5', 'o6', 'o7', 'o8', 'o9', 'o10', 'o20', 'o30', 'o40', 'o50', 'range'], ['low', 'high', 'u5', 'u10', 'u15', 'u20', 'u25', 'u30', 'u35', 'u40', 'u45', 'u50', 'u60', 'u70', 'u80', 'u90', 'u100', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'o35', 'o40', 'o45', 'o50', 'o60', 'o70', 'o80', 'o90', 'o100', 'range'], ['neg', 'pos', 'poslow', 'high', 'u5', 'u10', 'u15', 'u20', 'u25', 'u30', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'range'], ['neg', 'pos', 'poslow', 'high', 'u5', 'u10', 'u15', 'u20', 'u25', 'u30', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'range'], ['neg', 'pos', 'poslow', 'high', 'u5', 'u10', 'u15', 'u20', 'u25', 'u30', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'range'], ['neg', 'pos', 'poslow', 'high', 'u5', 'u10', 'u15', 'u20', 'u25', 'u30', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'range'], ['neg', 'pos', 'poslow', 'high', 'u5', 'u10', 'u15', 'u20', 'u25', 'u30', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'range'], ['neg', 'pos', 'poslow', 'high', 'u5', 'u10', 'u15', 'u20', 'u25', 'u30', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'range'], ['neg', 'pos', 'poslow', 'high', 'u5', 'u10', 'u15', 'u20', 'u25', 'u30', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'range'], ['none', 'pos', 'high', 'veryhigh', 'o1', 'o2', 'o3', 'o4', 'o5', 'o6', 'o7', 'o8', 'o9', 'o10', 'range'], ['pos', 'neg', 'verypos', 'veryneg', 'u-50', 'u-45', 'u-40', 'u-35', 'u-30', 'u-25', 'u-20', 'u-15', 'u-10', 'u-5', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'o35', 'o40', 'o45', 'o50', 'range'], ['pos', 'neg', 'verypos', 'veryneg', 'u-50', 'u-45', 'u-40', 'u-35', 'u-30', 'u-25', 'u-20', 'u-15', 'u-10', 'u-5', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'o35', 'o40', 'o45', 'o50', 'range'], ['pos', 'neg', 'verypos', 'veryneg', 'u-50', 'u-45', 'u-40', 'u-35', 'u-30', 'u-25', 'u-20', 'u-15', 'u-10', 'u-5', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'o35', 'o40', 'o45', 'o50', 'range'], ['high', 'low', 'u1', 'u0.5', 'o0.5', 'o1', 'o1.5', 'o2', 'o3', 'o4', 'o5', 'o10', 'range'], ['high', 'low', 'u1', 'u0.5', 'o0.5', 'o1', 'o1.5', 'o2', 'o3', 'o4', 'o5', 'o10', 'frange'], ['high', 'low', 'u1', 'u0.9', 'u0.8', 'u0.7', 'u0.6', 'u0.5', 'u0.4', 'u0.3', 'u0.2', 'u0.1', 'o0.1', 'o0.2', 'o0.3', 'o0.4', 'o0.5', 'o0.6', 'o0.7', 'o0.8', 'o0.9', 'o1', 'frange'], ['high', 'low', 'u1', 'u0.9', 'u0.8', 'u0.7', 'u0.6', 'u0.5', 'u0.4', 'u0.3', 'u0.2', 'u0.1', 'o0.1', 'o0.2', 'o0.3', 'o0.4', 'o0.5', 'o0.6', 'o0.7', 'o0.8', 'o0.9', 'o1', 'frange'], ['pos', 'neg', 'high', 'u90', 'u80', 'u70', 'u60', 'u50', 'u45', 'u40', 'u35', 'u30', 'u25', 'u20', 'u15', 'u10', 'u5', 'u0', 'u-10', 'u-20', 'u-30', 'u-50', 'u-70', 'u-100', 'o0', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'o35', 'o40', 'o45', 'o50', 'o60', 'o70', 'o80', 'o90', 'range'], ['pos', 'neg', 'veryneg', 'high', 'u90', 'u80', 'u70', 'u60', 'u50', 'u45', 'u40', 'u35', 'u30', 'u25', 'u20', 'u15', 'u10', 'u5', 'u0', 'u-10', 'u-20', 'u-30', 'u-50', 'u-70', 'u-100', 'o0', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'o35', 'o40', 'o45', 'o50', 'o60', 'o70', 'o80', 'o90', 'range'], ['pos', 'neg', 'veryneg', 'high', 'u90', 'u80', 'u70', 'u60', 'u50', 'u45', 'u40', 'u35', 'u30', 'u25', 'u20', 'u15', 'u10', 'u5', 'u0', 'u-10', 'u-20', 'u-30', 'u-50', 'u-70', 'u-100', 'o0', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'o35', 'o40', 'o45', 'o50', 'o60', 'o70', 'o80', 'o90', 'range'], ['none', 'pos', 'low', 'high', 'o0', 'o10', 'o20', 'o30', 'o40', 'o50', 'o60', 'o70', 'o80', 'o90', 'o100', 'u10', 'u20', 'u30', 'u40', 'u50', 'u60', 'u70', 'u80', 'u90', 'u100', 'range'], ['low', 'high', 'veryhigh', 'o10', 'o20', 'o30', 'o40', 'o50', 'o60', 'o70', 'o80', 'o90', 'range'], ['veryneg', 'neg', 'pos', 'verypos', 'u-90', 'u-80', 'u-70', 'u-60', 'u-50', 'u-45', 'u-40', 'u-35', 'u-30', 'u-25', 'u-20', 'u-15', 'u-10', 'u-5', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'o35', 'o40', 'o45', 'o50', 'o60', 'o70', 'o80', 'o90', 'range'], ['low', 'high', 'u90', 'u80', 'u70', 'u60', 'u50', 'u40', 'u30', 'u20', 'u10', 'o10', 'o20', 'o30', 'o40', 'o50', 'o60', 'o70', 'o80', 'o90', 'range'], ['veryneg', 'neg', 'pos', 'verypos', 'u-50', 'u-45', 'u-40', 'u-35', 'u-30', 'u-25', 'u-20', 'u-15', 'u-10', 'u-5', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'o35', 'o40', 'o45', 'o50', 'range'], ['low', 'high', 'u5', 'u10', 'u15', 'u20', 'u25', 'u30', 'o5', 'o10', 'o15', 'o20', 'o25', 'o30', 'range'], ['strongbuy', 'buybetter', 'buy', 'holdbetter', 'hold', 'holdworse', 'sell', 'sellworse', 'strongsell', 'modal'], ['option', 'short', 'optionshort'], ['today', 'todaybefore', 'todayafter', 'tomorrow', 'tomorrowbefore', 'tomorrowafter', 'yesterday', 'yesterdaybefore', 'yesterdayafter', 'nextdays5', 'prevdays5', 'thisweek', 'nextweek', 'prevweek', 'thismonth', 'modal'], ['dup', 'ddown', 'd15u', 'd10u', 'd5u', 'd5o', 'd10o', 'd15o', '1w30u', '1w20u', '1w10u', '1wdown', '1wup', '1w10o', '1w20o', '1w30o', '4w50u', '4w30u', '4w20u', '4w10u', '4wdown', '4wup', '4w10o', '4w20o', '4w30o', '4w50o', '13w50u', '13w30u', '13w20u', '13w10u', '13wdown', '13wup', '13w10o', '13w20o', '13w30o', '13w50o', '26w75u', '26w50u', '26w30u', '26w20u', '26w10u', '26wdown', '26wup', '26w10o', '26w20o', '26w30o', '26w50o', '26w100o', '52w75u', '52w50u', '52w30u', '52w20u', '52w10u', '52wdown', '52wup', '52w10o', '52w20o', '52w30o', '52w50o', '52w100o', '52w200o', '52w300o', '52w500o', 'ytd75u', 'ytd50u', 'ytd30u', 'ytd20u', 'ytd10u', 'ytd5u', 'ytddown', 'ytdup', 'ytd5o', 'ytd10o', 'ytd20o', 'ytd30o', 'ytd50o', 'ytd100o'], ['dup', 'ddown', 'd15u', 'd10u', 'd5u', 'd5o', 'd10o', 'd15o', '1w30u', '1w20u', '1w10u', '1wdown', '1wup', '1w10o', '1w20o', '1w30o', '4w50u', '4w30u', '4w20u', '4w10u', '4wdown', '4wup', '4w10o', '4w20o', '4w30o', '4w50o', '13w50u', '13w30u', '13w20u', '13w10u', '13wdown', '13wup', '13w10o', '13w20o', '13w30o', '13w50o', '26w75u', '26w50u', '26w30u', '26w20u', '26w10u', '26wdown', '26wup', '26w10o', '26w20o', '26w30o', '26w50o', '26w100o', '52w75u', '52w50u', '52w30u', '52w20u', '52w10u', '52wdown', '52wup', '52w10o', '52w20o', '52w30o', '52w50o', '52w100o', '52w200o', '52w300o', '52w500o', 'ytd75u', 'ytd50u', 'ytd30u', 'ytd20u', 'ytd10u', 'ytd5u', 'ytddown', 'ytdup', 'ytd5o', 'ytd10o', 'ytd20o', 'ytd30o', 'ytd50o', 'ytd100o'], ['wo3', 'wo4', 'wo5', 'wo6', 'wo7', 'wo8', 'wo9', 'wo10', 'wo12', 'wo15', 'mo2', 'mo3', 'mo4', 'mo5', 'mo6', 'mo7', 'mo8', 'mo9', 'mo10', 'mo12', 'mo15'], ['ob90', 'ob80', 'ob70', 'ob60', 'os40', 'os30', 'os20', 'os10', 'nob60', 'nob50', 'nos50', 'nos40', 'range'], ['u', 'u0', 'u1', 'u2', 'u3', 'u4', 'u5', 'u6', 'u7', 'u8', 'u9', 'u10', 'u15', 'u20', 'd', 'd0', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'd10', 'd15', 'd20', 'frange'], ['pb', 'pb10', 'pb20', 'pb30', 'pb40', 'pb50', 'pa', 'pa10', 'pa20', 'pa30', 'pa40', 'pa50', 'pc', 'pca', 'pcb', 'cross50', 'cross50a', 'cross50b', 'cross200', 'cross200a', 'cross200b', 'sa50', 'sb50', 'sa200', 'sb200'], ['pb', 'pb10', 'pb20', 'pb30', 'pb40', 'pb50', 'pa', 'pa10', 'pa20', 'pa30', 'pa40', 'pa50', 'pc', 'pca', 'pcb', 'cross20', 'cross20a', 'cross20b', 'cross200', 'cross200a', 'cross200b', 'sa20', 'sb20', 'sa200', 'sb200'], ['pb', 'pb10', 'pb20', 'pb30', 'pb40', 'pb50', 'pb60', 'pb70', 'pb80', 'pb90', 'pa', 'pa10', 'pa20', 'pa30', 'pa40', 'pa50', 'pa60', 'pa70', 'pa80', 'pa90', 'pa100', 'pc', 'pca', 'pcb', 'cross20', 'cross20a', 'cross20b', 'cross50', 'cross50a', 'cross50b', 'sa20', 'sb20', 'sa50', 'sb50'], ['u', 'u1', 'u2', 'u3', 'u4', 'u5', 'u6', 'u7', 'u8', 'u9', 'u10', 'u15', 'u20', 'd', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'd10', 'd15', 'd20', 'frange'], ['u', 'u1', 'u2', 'u3', 'u4', 'u5', 'u6', 'u7', 'u8', 'u9', 'u10', 'u15', 'u20', 'd', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'd10', 'd15', 'd20', 'frange'], ['nh', 'nl', 'b5h', 'b10h', 'b15h', 'b20h', 'b30h', 'b40h', 'b50h', 'b0to3h', 'b0to5h', 'b0to10h', 'a5h', 'a10h', 'a15h', 'a20h', 'a30h', 'a40h', 'a50h', 'a0to3h', 'a0to5h', 'a0to10h'], ['nh', 'nl', 'b5h', 'b10h', 'b15h', 'b20h', 'b30h', 'b40h', 'b50h', 'b0to3h', 'b0to5h', 'b0to10h', 'a5h', 'a10h', 'a15h', 'a20h', 'a30h', 'a40h', 'a50h', 'a0to3h', 'a0to5h', 'a0to10h'], ['nh', 'nl', 'b5h', 'b10h', 'b15h', 'b20h', 'b30h', 'b40h', 'b50h', 'b60h', 'b70h', 'b80h', 'b90h', 'b0to3h', 'b0to5h', 'b0to10h', 'a5h', 'a10h', 'a15h', 'a20h', 'a30h', 'a40h', 'a50h', 'a60h', 'a70h', 'a80h', 'a90h', 'a100h', 'a120h', 'a150h', 'a200h', 'a300h', 'a500h', 'a0to3h', 'a0to5h', 'a0to10h'], ['horizontal', 'horizontal2', 'tlresistance', 'tlresistance2', 'tlsupport', 'tlsupport2', 'wedgeup', 'wedgeup2', 'wedgedown', 'wedgedown2', 'wedgeresistance', 'wedgeresistance2', 'wedgesupport', 'wedgesupport2', 'wedge', 'wedge2', 'channelup', 'channelup2', 'channeldown', 'channeldown2', 'channel', 'channel2', 'doubletop', 'doublebottom', 'multipletop', 'multiplebottom', 'headandshoulders', 'headandshouldersinv', 'modal'], ['lls', 'lus', 'h', 'ih', 'stw', 'stb', 'd', 'dd', 'gd', 'mw', 'mb', 'modal'], ['u0', 'u0.5', 'u1', 'u1.5', 'u2', 'o0', 'o0.5', 'o1', 'o1.5', 'o2', 'o2.5', 'o3', 'o4', '0to0.5', '0to1', '0.5to1', '0.5to1.5', '1to1.5', '1to2', 'frange'], ['o0.25', 'o0.5', 'o0.75', 'o1', 'o1.5', 'o2', 'o2.5', 'o3', 'o3.5', 'o4', 'o4.5', 'o5', 'u0.25', 'u0.5', 'u0.75', 'u1', 'u1.5', 'u2', 'u2.5', 'u3', 'u3.5', 'u4', 'u4.5', 'u5', 'frange'], ['u50', 'u100', 'u500', 'u750', 'u1000', 'o50', 'o100', 'o200', 'o300', 'o400', 'o500', 'o750', 'o1000', 'o2000', '100to500', '100to1000', '500to1000', '500to10000', 'range'], ['o10', 'o5', 'o3', 'o2', 'o1.5', 'o1', 'o0.75', 'o0.5', 'o0.25', 'u2', 'u1.5', 'u1', 'u0.75', 'u0.5', 'u0.25', 'u0.1', 'frange'], ['u50', 'u100', 'u500', 'u750', 'u1000', 'o0', 'o50', 'o100', 'o200', 'o300', 'o400', 'o500', 'o750', 'o1000', 'o2000', 'o5000', 'o10000', 'o20000', 'range'], ['u1', 'u2', 'u3', 'u4', 'u5', 'u7', 'u10', 'u15', 'u20', 'u30', 'u40', 'u50', 'o1', 'o2', 'o3', 'o4', 'o5', 'o7', 'o10', 'o15', 'o20', 'o30', 'o40', 'o50', 'o60', 'o70', 'o80', 'o90', 'o100', '1to5', '1to10', '1to20', '5to10', '5to20', '5to50', '10to20', '10to50', '20to50', '50to100', 'range'], ['a50', 'a40', 'a30', 'a20', 'a10', 'a5', 'above', 'below', 'b5', 'b10', 'b20', 'b30', 'b40', 'b50'], ['today', 'yesterday', 'prevweek', 'prevmonth', 'prevquarter', 'prevyear', 'more1', 'more5', 'more10', 'more15', 'more20', 'more25']]
Update with find_all()
page = requests.get('https://www.finviz.com/screener.ashx?v=111&ft=4')
soup = BeautifulSoup(page.text, 'html.parser')
filters = soup.find_all('select', attrs={'data-filter': True})
finallist=[]
for f in filters:
options = f.find_all('option', attrs={'value': True})
option_list = []
for option in options:
if option['value']!="":
option_list.append(option['value'])
finallist.append(option_list)
print(finallist)
UPDATE with pandas.
page = requests.get('https://www.finviz.com/screener.ashx?v=111&ft=4')
soup = BeautifulSoup(page.text, 'html.parser')
filters = soup.find_all('select', attrs={'data-filter': True})
filter_list = []
for f in filters:
filter_list.append(f.get('data-filter'))
print(filter_list)
finallist=[]
for f in filters:
options = f.find_all('option', attrs={'value': True})
option_list = []
for option in options:
if option['value']!="":
option_list.append(option['value'])
finallist.append(option_list)
print(finallist)
df=pd.DataFrame([finallist],columns=filter_list)
print(df)
df.to_csv("outputdate.csv" , index=False)
Answered By - KunduK
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.