Created
January 26, 2017 21:31
-
-
Save p3t3r67x0/e62b0993a40ae76c4630d5f20d69206b to your computer and use it in GitHub Desktop.
Extract links from a given html document with you must call as first argument
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
#!/usr/bin/env python | |
import sys | |
from lxml import html | |
def main(): | |
filename = sys.argv[1] | |
with open(filename, 'rb') as f: | |
lines = f.readlines() | |
line = ','.join(lines) | |
str = html.document_fromstring(line) | |
x = str.xpath('//a/@href') | |
with open('urls.txt', 'wb') as f: | |
for i in x: | |
f.write('{}\n'.format(i)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment