Quantcast

Jump to content


Photo

Alternative to Beautiful Soup (Python)

python

  • Please log in to reply
7 replies to this topic

#1 shaggy111

shaggy111
  • 30 posts

Posted 16 September 2012 - 08:31 PM

Im working on a project and plan to port it to my android phone.

import urllib2
from BeautifulSoup import BeautifulSoup

while True:
title=raw_input ("Title: ")
# Type e to exit
if (title == "e"):
	 break;

author=raw_input ("Author: ")
# Replace Spaces with + symbol for URL
author = author.replace(" " , "+")
title = title.replace(" " , "+")

webpage="http://www.abebooks.com/servlet/SearchResults?an=" + author + "&bi=h&bx=off&dj=on&ds=30&fe=on&recentlyadded=all&sortby=17&sts=t&tn=" + title
web = urllib2.urlopen(webpage)
soup=BeautifulSoup(web)

# Search Webpage for Price and retrieve Text
price = soup.find('span', attrs={'class' : 'price'}).getText()

# Print the Results
print ("New: " + price + "\n")

I am pretty sure I can not install Beautiful Soup onto my phone so I was wondering how I would go about fixing this?

Edit: Seems my code lost indenting upon transfer.

Edited by shaggy111, 16 September 2012 - 08:31 PM.


#2 ShadowLink64

ShadowLink64
  • 16735 posts


Users Awards

Posted 16 September 2012 - 08:32 PM

HTMLParser isn't as nice, but it's bundled with the python core and you can still use it to find certain values for attributes and stuff.

#3 shaggy111

shaggy111
  • 30 posts

Posted 16 September 2012 - 08:35 PM

HTMLParser isn't as nice, but it's bundled with the python core and you can still use it to find certain values for attributes and stuff.


I am using SL4A on my Android phone. Would HTMLParser still work?

#4 Irradium

Irradium
  • Pyro (699) Maniac

  • 892 posts


Users Awards

Posted 17 September 2012 - 01:23 AM

I am using SL4A on my Android phone. Would HTMLParser still work?


SL4A is essentially Python running on the native C binaries of Android, the only things that won't work in the latest stable release are platform-specific modules, I believe; in short, yes. However, if you're using SL4A, why not try and cross compile BS4 for Android? It looks pretty small in comparison to other large Python projects out there, and you can exclude anything you don't use in your project. (http://code.google.c...BuildingModules)

#5 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 17 September 2012 - 02:38 AM

If it's intended for an Android phone wouldn't you be better off doing it in Java rather than Python and doing it as a proper application? Java has jsoup which is the equivalent to BeautifulSoup too.

#6 Josh

Josh
  • 318 posts

Posted 17 September 2012 - 05:37 AM

If it's intended for an Android phone wouldn't you be better off doing it in Java rather than Python and doing it as a proper application? Java has jsoup which is the equivalent to BeautifulSoup too.


This. No need to reinvent the wheel.

#7 artificial

artificial
  • 186 posts


Users Awards

Posted 17 September 2012 - 05:44 AM

Or if you're intent on Python use standard string parsing/regular expressions.

#8 Hydrogen

Hydrogen
  • Neocodex Co-Founder

  • 22213 posts


Users Awards

Posted 17 September 2012 - 07:09 AM

Or if you're intent on Python use standard string parsing/regular exp<b></b>ressions.

Then you'll have two problems ;).



Also tagged with one or more of these keywords: python

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users