[Python]python crawler Simple trial

Source: Internet
Author: User

has been using the python3.4 version, so only use the Urllib crawl data, and then use BeautifulSoup as analysis.

1, first installs the BeautifulSoup, executes the command as follows:

Pip Install BeautifulSoup4

2, the second step began to write code, to my blog as an example, in fact, the code is very simple

From urllib import requestfrom bs4 Import BEAUTIFULSOUPFP = Request.urlopen ("http://www.cnblogs.com/youyuan1980/") HTML = Fp.read () soup = beautifulsoup (html, ' Html.parser ') for Div in Soup.find_all (' A ', attrs={"class": "PostTitle2"}):    Print (Div.get (' href '))        #显示a标签属性的href    print (' Text: ' +div.get_text ()) #显示a标签里面的text

Don't explain, just look and see.

[Python]python crawler Simple trial

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.