The code below is for scraping data from webpage.Actually,the output from this code
and output from the another list is to be considered .
list2=[]
###-I am collecting all span tags ,storing as text in variable called alpha.
for i in range(len(contents)):
for j in contents[i].findAll('span'):
alpha=j.text
# print(alpha)
alphachar=re.sub('[^a-zA-Z]+', '', alpha) #I am eliminating empty lists.
alphabets=alphachar.split() #converting to list
for item in alphabets:
if item!=[]:
list2.append(item) #I am appending to lists
for (a, b) in zip(li,list2):
print(a,b)
The output of the above code is :
AMD AdvancedMicroDevicesInc
BAC BankofAmericaCorp
GE GeneralElectricCo
F FordMotorCo
M MacysInc
PFE PfizerInc
FCX FreeportMcMoRanInc
BMY BristolMyersSquibbCo
T ATTInc
JWN NordstromInc
JWN NordstromInc
M MacysInc
LB LBrandsInc
GPS GapInc
SJM JMSmuckerCo
CPRI CapriHoldingsLtd
RL RalphLaurenCorp
BIIB BiogenInc
FCX FreeportMcMoRanInc
ADS AllianceDataSystemsCorp
Now I have another list called name :
name = allbody.findAll('h3')
Its output is:
Most actives,Gainers
Now,I want the output as:
- Most actives
AMD AdvancedMicroDevicesInc
BAC BankofAmericaCorp
GE GeneralElectricCo
F FordMotorCo
M MacysInc
PFE PfizerInc
FCX FreeportMcMoRanInc
BMY BristolMyersSquibbCo
T ATTInc
JWN NordstromInc
- Gainers
JWN NordstromInc
M MacysInc
LB LBrandsInc
GPS GapInc
SJM JMSmuckerCo
CPRI CapriHoldingsLtd
RL RalphLaurenCorp
BIIB BiogenInc
FCX FreeportMcMoRanInc
ADS AllianceDataSystemsCorp
I tried using nested for loop for names and zip function but didnt work out.Can anyone please help out in this?