import sys import json import requests from bs4 import BeautifulSoup import codecs def scraping(url, output_name): # get a HTML response response = requests.get(url) html = response.text.encode(response.encoding) # prevent encoding errors # parse the response soup = BeautifulSoup(html, "lxml") # extract ## title header = soup.find("head") title = header.find("title").text ## description descriptio
HIGH-DETAIL MINIATURES ON FDM: THE POWER OF A 0.2MM NOZZLEI tested a 0.2mm nozzle on my Bambu X1 Carbon to see if it could deliver resin-like detail without the hassle of resin printing. After printing, priming, and painting a detailed miniature in a single day, I was genuinely impressed with the quality and ease of the process. read more DECODING WEATHER STATION RADIOI decode and “hack” a consume
自然言語処理では、しばしばコーパスを作るためにWeb上のリソースを利用します。そのためにスクレイピングをするのですが、大量のリクエストを特定のサイトに送るとBanされる可能性があります。今回はそれを防ぐ一つの方法を書きます。(悪用厳禁) TL;DR 概要 コード例 metadata.py requestsを使った接続 サーバリストの見つけ方 参考 TL;DR VPNを使おう。 概要 nordvpnのようなVPNを使えば、数十の国の数千のサーバを利用することができます。もし、これらの膨大なサーバリストを使ってスクレイピングに利用することができれば、以下の2つのメリットがあります: ランダムにIPを変え続ければブロックされる可能性が下がり、仮にブロックされても別のサーバーのIPを使えばいい。 複数のサーバのIPを利用してスクレイピングするので、並列化すれば、time.sleepの間隔を長めにし
Advanced Python Web Scraping: Best Practices & Workarounds Here are some helpful tips for web scraping with Python. Scraping is a simple concept in its essence, but it's also tricky at the same time. It's like a cat and mouse game between the website owner and the developer operating in a legal gray area. This article sheds light on some of the obstructions a programmer may face while web scraping
An approach using Scrapy will make use of two components, RandomProxy and RotateUserAgentMiddleware. Modify DOWNLOADER_MIDDLEWARES as follows. You will have to insert the new components in the settings.py: DOWNLOADER_MIDDLEWARES = { 'scrapy.contrib.downloadermiddleware.retry.RetryMiddleware': 90, 'tutorial.randomproxy.RandomProxy': 100, 'scrapy.contrib.downloadermiddleware.httpproxy.HttpProxyMiddl
requestsを使ってAPIからデータ取ろうと思った時に調べたこと。 まずはリトライ設定をしつつAPIの内容をローカルファイルにダウンロードする処理。リトライについてはAdapterを使うらしい。下記を参考にした。 http://www.mobify.com/blog/http-requests-are-hard/ ダウンロードする方法として、下記Stackoverflowのページを参考にした。requests.getにstream=Trueを設定することでファイルサイズが大きくてもメモリサイズを食わずにダウンロードできる。 http://stackoverflow.com/questions/16694907/how-to-download-large-file-in-python-with-requests-py import requests def download(url, o
Pythonurllib.urlopenはステータス404でも例外を発生してくれない。urllib2.urlopenはそのままだと環境変数のプロキシ設定を参照してするようで、ちょっと困る場合があった。というわけで、urllib2.urlopenでプロキシを設定|参照しないようにする方法。 #!/usr/bin/env python import urllib2 #今回はプロキシ設定を空にしておく #proxies = {'http': 'http://www.example.com:3128/'} proxies = {} #プロキシハンドラーの作成して handler = urllib2.ProxyHandler(proxies) #プロキシハンドラーを指定してURL Openerを作成して opener = urllib2.build_opener(handler) #作成したURL
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く