>  기사  >  백엔드 개발  >  Python3.4 기반의 간단한 크롤러 기능에 대한 자세한 소개

Python3.4 기반의 간단한 크롤러 기능에 대한 자세한 소개

巴扎黑
巴扎黑원래의
2017-09-16 10:16:361520검색

이 글은 주로 간단한 크롤링 및 크롤러 기능을 구현하기 위한 Python3.4 프로그래밍을 소개하며, Python3.4 웹 페이지 크롤링 및 정기적인 파싱 관련 작업 기술이 필요하면 참고할 수 있습니다.

이 글의 예는 Python3.4의 간단한 구현을 알려줍니다. Python3.4 프로그래밍 크롤링 크롤러 기능. 참고할 수 있도록 모든 사람과 공유하세요. 세부 사항은 다음과 같습니다:


import urllib.request
import urllib.parse
import re
import urllib.request,urllib.parse,http.cookiejar
import time
def getHtml(url):
  cj=http.cookiejar.CookieJar()
  opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
  opener.addheaders=[('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36'),('Cookie','4564564564564564565646540')]
  urllib.request.install_opener(opener)
  page = urllib.request.urlopen(url)
  html = page.read()
  return html
#print ( html)
#html = getHtml("http://weibo.com/")
def getimg(html):
  html = html.decode('utf-8')
  reg='"screen_name":"(.*?)"'
  imgre = re.compile(reg)
  src=re.findall(imgre,html)
  return src
#print ("",getimg(html))
uid=['2808675432','3888405676','2628551531','2808587400']
for a in list(uid):
  print (getimg(getHtml("http://weibo.com/"+a)))
  time.sleep(1)

위 내용은 Python3.4 기반의 간단한 크롤러 기능에 대한 자세한 소개의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.