beautifulsoup - Python - How to move output text to the left / up? -
#!/usr/bin/python __future__ import print_function import textwrap import requests bs4 import beautifulsoup def bbb_spider(max_pages): bus_cat = raw_input('enter business category: ') pages = 1 while pages <= max_pages: url = 'http://www.bbb.org/search/?type=category&input=' + str(bus_cat) + '&page=' + str(pages) sauce_code = requests.get(url) plain_text = sauce_code.text soup = beautifulsoup(plain_text, "html.parser") link in soup.select("table.search-results-table tr h4 a"): href = link.get('href') bbb_profiles(href) pages += 1 def bbb_profiles(profile_urls): sauce_code = requests.get(profile_urls) plain_text = sauce_code.text soup = beautifulsoup(plain_text, "html.parser") business_name in soup.findall("h1", {"class": "business-title"}): print(business_name.string) business_phone in soup.findall("span", {"class": "business-phone"}): print(business_phone.string) business_address in soup.select("div.business-detail-text p span.nobr"): print(business_address.string, end=" ") sort_pages = input('how many pages sort through?: ') bbb_spider(sort_pages) so have output looks this:
phone address name of business what have is:
name of business phone address basically what's happening here throughout foreach loop, next block of items arranged how i'd (name, phone, address), name on same line previous address's block. i'm trying bring name down , left, address left, , phone fine is.
use .get_text(strip=true) instead of .string:
print(business_name.get_text(strip=true))
Comments
Post a Comment