【发布时间】:2020-01-10 04:02:57
【问题描述】:
我已经有了一个工作 python 脚本,但我想自动从页面获取 url。我只需要 div 类 se_component_wrap sect_dsc __se_component_area 中的所有 html 代码,但目前我正在获取整个 html页面
from lxml import html
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen as uReq
from fetch import *
my_url=('https://m.post.naver.com/viewer/postView.nhn?volumeNo=20163796&memberNo=29747755')
#Opening Client
uClient = uReq(my_url)
#Opening the client
page_html = uClient.read()
#Closing connection
uClient.close()
page_soup = soup(page_html, "html.parser")
clear_file=page_soup.prettify()
with open("test.txt","w", encoding="utf-8") as outp:
outp.write(clear_file)
print (page_soup)
fetcher()
我希望输出是包含在该部门中的 html 代码,而不是完整的页面
【问题讨论】:
-
即输出页面中的文字..我要分区的html代码..
-
您的绳子目前设计用于刮掉整个页面。你想要什么部门标签?目标页面上有100个划分标签。
-
se_component_wrap sect_dsc __se_component_area
-
虽然我想要那个部门标签内的所有代码..
标签: html python-3.x beautifulsoup python-requests lxml