파충류 기술 - 사진 혼합 된 텍스트, 영상 위치가 문자열 URL로 대체됩니다

# -*- coding: utf-8 -*-

import pprint
import requests as req
import re
from bs4 import BeautifulSoup

url = "https://www.taoguba.com.cn/Article/2336826/1"
content = req.get(url).text
s_html = re.findall(r"<!-- 主贴内容开始 -->(.*?)<!-- 主贴内容结束 -->", content, re.S | re.M)[0]
soup = BeautifulSoup(s_html, 'lxml')
imgs = soup.find_all(attrs={'data-type': 'contentImage'})
urls = [img['data-original'] for img in imgs]
s_imgs = re.findall(r"<img.*?/>", s_html)   # 非贪婪匹配
match_info = dict(zip(s_imgs, urls))

for s_img in s_imgs:
    s_html = s_html.replace(s_img, match_info.get(s_img))

soup = BeautifulSoup(s_html, 'lxml')
text = soup.div.text.strip()
print(pprint.pformat(text))

그림 삽입 설명 여기
업데이트 : 2019년 12월 27일

게시 된 291 개 원래 기사 · 원의 찬양 (104) · 전망 (410) 000 +

추천

출처blog.csdn.net/Enjolras_fuu/article/details/103732643