Last active
July 7, 2020 02:39
-
-
Save miyo/6c06763154e997c215903dcabe91dcc4 to your computer and use it in GitHub Desktop.
A simple web scraping example
This file contains 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
# THIS IS AN EXAMPLE SCRIPT OF WEB SCRAPING | |
# DO NOT ATACK THE WEB SITE | |
import requests | |
from bs4 import BeautifulSoup | |
import re | |
import sys | |
import urllib | |
if len(sys.argv) < 2: | |
print("python3 {} PRICE".format(sys.argv[0])) | |
sys.exit() | |
price = sys.argv[1] | |
url = "https://www.biccamera.com/bc/category/?q=LAN%83P%81%5B%83u%83%8B&max={0}&min={0}".format(price) | |
ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) '\ | |
'AppleWebKit/537.36 (KHTML, like Gecko) '\ | |
'Chrome/55.0.2883.95 Safari/537.36 ' | |
req = urllib.request.Request(url, headers={'User-Agent': ua}) | |
html = urllib.request.urlopen(req) | |
soup = BeautifulSoup(html, "html.parser") | |
#<div class="bcs_listItem" data-item-list-area="商品一覧_" id="ga_itam_list"> | |
item_list = soup.find('div', attrs={'class' : 'bcs_listItem'}) | |
if item_list is None: | |
print("none") | |
sys.exit() | |
items = item_list.find_all('li') | |
for item in items: | |
print(item.attrs['data-item-name']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment