Python Crawl site URL gadget

Source: Internet
Author: User

1. Install the Python requests module (via PIP):

The environment has been built!

2, test the process of crawling URLs:

Crawled out of the URL has JavaScript code, the regular on still need to be more perfect, interested can study next ~!

Tool Source code:

#coding: Utf-8

Import Sys

Import re

Import requests

#获取输入URL and get the page text

input = raw_input ("Please input URL, format like this (http://www.baidu.com):")

print ' Input:%s '% input

R = requests.get (input)

data = R.text

#利用正则查找所有URL

Link_list =re.findall (r "<=href=\"). +? =\")| (? <=href=\ '). +? (? =\ ') ", data)

Count = 0

For URL in link_list:

File = Open ("C:\\Test.txt", "a")

File.write (url+ "\ n")

Count = Count + 1

Print URL

print ' \ n '

print ' Total URL is: ' + str (count)

print ' \ n '

print ' crawling achieve ... '

File.close ()

Python Crawl site URL gadget

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.