从本地文件python访问源代码

时间:2016-08-02 13:49:11

标签: python selenium beautifulsoup local inspect

我需要访问本地保存文件的源代码,但我需要自动执行此操作,因为一个文件夹中有多个文件。我看了检查模块和selenium模块,但我仍然明白该怎么做。访问源代码后,我需要使用bs4从中提取。

我在这里和其他地方看过几个有类似问题的帖子,但问题是我的文件没有在源代码中打开(它是用xml编写的,到目前为止所有内容都需要在源代码中才能使用这些模块)。如果我打开文件,它只是使用我的浏览器打开常规页面,然后我必须单击查看页面源。

如何自动执行此操作以便打开页面,转到源代码并保存,以便将其粘贴到汤中以便以后解析?

path_g_jurt = r'C:\Users\g\Desktop\t\SDU\jurt htmls\jurt\meta jurt'

file = r'C:\Users\g\Desktop\t\SDU\jurt htmls\jurt\meta jurt' + "/" + file

for file in path_g_jurt:
if file.endswith(".xhtml"):
with open(file, encoding = "utf-8") as mdata_jurt:

soup = BeautifulSoup(mdata_jurt)
main = file.find("jcid").get_text()
misc_links = []
for item in file.find_all("regelgeving"):
    misc = item.find("misc:link")
    misc_links.append(misc.get("misc:jcid"))

任何帮助将不胜感激。

0 个答案:

没有答案