Skip to content

Instantly share code, notes, and snippets.

@dgtlmoon
Created February 22, 2017 09:41
Show Gist options
  • Save dgtlmoon/d013d0a517c1ff408de7f21a34c7f8cd to your computer and use it in GitHub Desktop.
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
#!/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
@dgtlmoon
Copy link
Author

<title>Xiaomi Mi Max - Full phone specifications</title>
<title>Xiaomi Redmi 3 - Full phone specifications</title>
<title>Xiaomi Redmi 3 Pro - Full phone specifications</title>
<title>Xiaomi Mi 5s Plus - Full phone specifications</title>
<title>Xiaomi Redmi 3s - Full phone specifications</title>
<title>Xiaomi Redmi Note 3 - Full phone specifications</title>
<title>Xiaomi Mi Note 2 - Full phone specifications</title>
<title>Xiaomi Mi 5 - Full phone specifications</title>
<title>Xiaomi Redmi 4 Prime - Full phone specifications</title>
<title>Xiaomi Redmi 3s Prime - Full phone specifications</title>
<title>Xiaomi Redmi Note 4 (MediaTek) - Full phone specifications</title>
<title>Huawei Mate 9 - Full phone specifications</title>
<title>Xiaomi Redmi Pro - Full phone specifications</title>
<title>ZTE nubia Z11 - Full phone specifications</title>
<title>Xiaomi Mi 4s - Full phone specifications</title>
<title>Huawei Honor 8 - Full phone specifications</title>
<title>Huawei P9 Plus - Full phone specifications</title>
<title>LG V20 - Full phone specifications</title>
<title>LeEco Le Max 2 - Full phone specifications</title>
<title>LG G5 - Full phone specifications</title>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment