環境 MacBookPro14,1 python3.7
pythonで sys と seleniumから webdriver をimportしています。
http://gihyo.jp/book/2017/978-4-7741-8367-1
Pythonクローリング&スクレイピングをもとにnoteのスクレイピングを試みています。
個別のnoteからURL、タイトル、概要を取得したいです。そのため本の中のこの関数(古くなったのかこちらの https://note.mu/ のトップページでも機能しない関数)をいじっています。
def scrape_posts(driver): posts = [] for a in driver.find_elements_by_css_selector('a.p-post--basic'): posts.append({ 'url': a.get_attribute('href'), 'title': a.find_element_by_css_selector('h4').text, 'description': a.find_element_by_css_selector('.c-post__description').text, }) return posts
上記関数をいじって例えば Dai先生のnote https://note.mu/daikawai からURL、タイトル、概要を取得したいです。
def scrape_posts(driver): posts = [] for a in driver.find_elements_by_css_selector('div.renewal-p-cardItem'): posts.append({ 'url': a.get_attribute('href'), 'title': a.find_element_by_css_selector('h3').text, 'description': a.find_element_by_css_selector('.renewal-p-cardItem__description').text, }) return posts
タイトル、概要は取得できたのですが、URLが取得できません。
https://note.mu/daikawai の記事のURLを取得するのに 上記 href はなにと取り替えればよいでしょうか?
教えてください。よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/30 04:34