html - string search returns none or [] -
i have several urls want open specific place , search specific name i'm getting none returned or [].
i have searched cannot see reply pertinent code.
from bs4 import beautifulsoup urllib import request webpage = request.urlopen("http://www.dsfire.gov.uk/news/newsdesk/incidentspast7days.cfm?sitecategoryid=3&t1id=26&t2id=35") soup = beautifulsoup(webpage) incidents = soup.find(id="collapsiblepanel1") links = [] line in incidents.find_all('a'): links.append("http://www.dsfire.gov.uk/news/newsdesk/"+line.get('href')) n = 0 e = len(links) while n < e: webpage = request.urlopen(links[n]) soup = beautifulsoup(webpage) station = soup.find(id="incidentdetailcontainer") #search string print(soup.body.findall(text='ashburton')) n=n+1
i know in lastly link found on page.
thanks in advance ideas or comments
if ouput "[]" only, means output array. have set index => variable[index].
try one
print(soup.body.findall(text='ashburton')[0])
...where storing variable first easier:
search = soup.body.findall(text='ashburton') print(search[0])
this bring first found item.
for printing found items go
search = soup.body.findall(text='ashburton') foreach(entry in search) print(entry)
notice more pseude-code instead of working example. dont know beautifulsoap.
html string list search beautifulsoup
No comments:
Post a Comment