urllib | URL handling module |
import urllib.request openurl = 'URLを指定' savefile = 'ファイル名を指定' urllib.request.urlretrieve(openurl, savefile)urlretrieveはレガシー・インタフェイスとして、Python 2のモジュールurllibから移植された。
将来、廃止されるかもしれない。
urlretrieveを使わない方法
import urllib.request openurl = 'URLを指定' savefile = 'ファイル名を指定' ret = urllib.request.urlopen(openurl).read() with open(savefile, mode="wb") as f: f.write(ret)
downloader | Download Files over HTTP and HTTPS |
library(downloader) openurl = "URLを指定" savefile = "ファイル名を指定" download(openurl, savefile)
beautifulsoup | Python library designed for quick turnaround projects like screen-scraping |
from bs4 import BeautifulSoup import urllib.request as req openurl = 'URLを指定' res = req.urlopen(openurl) soup = BeautifulSoup(res, 'html.parser')
soup.title | titleタグを取得 |
soup.title.string | titleタグの文字列を取得 |
soup.p | 一番最初のpタグを取得 |
soup.p['class'] | pタグに指定されたクラス名を取得 |
soup.find_all('a') | すべてのaタグを取得 |
soup.find(id="link3") | idにlink3と指定されたタグを取得 |
readHTMLTable | Read Data From One Or More HTML Tables |
library(XML) myurl = "URLを指定" readHTMLTable(myurl)
read_html | Parse An HTML Page. |
html_nodes | Select Nodes From An HTML Document |
html_node | |
html_text | Extract Attributes, Text And Tag Name From Html. |
html_attr |
library(rvest) library(stringr) my_url = "URLを指定" ret = read_html(myurl) ret %>% html_node("h1") %>% html_text() ret %>% html_nodes("a") %>% htrml_attr("href")
re | Regular expression operations |
import re regex = '正規表現を指定' mystr = '検索対象文字列を指定' print(re.match(regex, mystr))
import re regex = '正規表現を指定' mystr = '検索対象文字列を指定' ret = re.compile(regex) print(ret.match(mystr)
stringr | Simple, Consistent Wrappers for Common String Operations |
library(stringr) fruit <- c("apple", "banana", "pear", "pinapple") str_subset(fruit, "^a") str_subset(fruit, "a$")
タグ
最新コメント