用python从桌面解析HTML

2024-10-02 12:23:49 发布

您现在位置:Python中文网/ 问答频道 /正文

假设我需要从这里收取信息费 网站: http://www.smv.gob.pe/Frm_ValorCuotaDetalle_V2.aspx?in_ac_pre_ope=A&in_ad_fecha=31/01/2017

但是由于我在代理方面遇到了问题,我所做的就是从web上复制源代码并将其粘贴到名为test222.html的记事本文件中。你知道吗

我想读它与美丽的汤,以操纵它,但我真的不知道怎么做。test222.html文档在我的桌面上。 我现在所有的代码都是。。。你知道吗

from bs4 import BeautifulSoup

web_parsed = 'C:/Users/Desktop/test222.html'

soup = BeautifulSoup(web_parsed, 'html.parser')

print soup

提前谢谢


Tags: inwebhttp网站htmlwwwparsedpe
1条回答
网友
1楼 · 发布于 2024-10-02 12:23:49

BeautifulSoup需要一个HTML字符串,因此需要先读取文件:

with open(r'C:/Users/Desktop/test222.html') as f:
    html = f.read()

soup = BeautifulSoup(html , 'html.parser')
print soup

相关问题 更多 >

    热门问题