Skip to content

Instantly share code, notes, and snippets.

@YoshihitoAso
Created February 27, 2014 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YoshihitoAso/9248451 to your computer and use it in GitHub Desktop.
Save YoshihitoAso/9248451 to your computer and use it in GitHub Desktop.
[Python][PyQuery]pyqueryでスクレイピング

pyqueryでスクレイピング

pyqueryを使ってスクレイピングしてみたのでメモ

インストールは

pip install pyquery

でOK。pyqueryが依存しているlxmlもあわせてインストールされる。

from pyquery import PyQuery
q = PyQuery(url='http://b.hatena.ne.jp/')

for elem in q.find('a.entry-link'):
#PyQuery
    q2 = PyQuery(elem)
    print q2.text()
    print q2.attr('href')
    
#lxml
#    print elem.text
#    print elem.get('href')

こんな感じで使える。

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