Created
February 22, 2017 09:41
-
-
Save dgtlmoon/d013d0a517c1ff408de7f21a34c7f8cd to your computer and use it in GitHub Desktop.
Python BeutifulSoup4 quick hack to find me a phone released in 2016 with an Infrared port
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Add your regex to find your phone | |
# Horrible lazy fast script | |
from bs4 import BeautifulSoup | |
import urllib2 | |
import re | |
response = urllib2.urlopen('http://www.gsmarena.com/battery-test.php3') | |
html_doc = response.read() | |
soup = BeautifulSoup(html_doc, 'html.parser') | |
tables = soup.find_all('table') | |
rows=tables[1].find_all('tr'); | |
for row in rows: | |
cell = row.find_all('td', {'class': 'lalign'}); | |
if cell and len(cell[0]): | |
x = "%s" % (cell[0]) | |
m = re.search('a href="(.+)"', x) | |
sub_response = urllib2.urlopen("http://www.gsmarena.com/%s" % m.group(1) ) | |
phone_res = sub_response.read() | |
phone_soup = BeautifulSoup(phone_res, 'html.parser') | |
if re.search('Infrared port', phone_res) and re.search('Released 2016', phone_res): | |
print phone_soup.title |
Author
dgtlmoon
commented
Feb 22, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment