Created
December 11, 2017 15:18
-
-
Save hyoiutu/2da4047552bc0df62c801bfceba69f49 to your computer and use it in GitHub Desktop.
SSまとめサイトのリンクのリストを取得
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
import functools as ft | |
import lxml.html | |
from selenium import webdriver | |
import re | |
def get_link(): | |
driver = webdriver.PhantomJS() | |
for page in range(1,1612+1): | |
url = f"http://ssmania.info/category/%E3%83%87%E3%83%AC%E3%83%9E%E3%82%B9?page={page}" | |
driver.get(url) | |
root = lxml.html.fromstring(driver.page_source) | |
link_urls = [link_element.get("href") for link_element in root.cssselect('a.articlelink')] | |
print(link_urls) | |
yield link_urls | |
get_link_gen = get_link() | |
with open("linkes.dat", "w") as f: | |
for links in get_link_gen: | |
for link in links: | |
print(link) | |
f.write(link) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment