Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 在web代码中查找href html时遇到问题_Python 3.x - Fatal编程技术网

Python 3.x 在web代码中查找href html时遇到问题

Python 3.x 在web代码中查找href html时遇到问题,python-3.x,Python 3.x,我正在学习python。由于我是新手,我不允许使用Python的内置库,除非有人告诉我。对于这个问题,我将查找“”的各个href位置。我在这里看到了更多的答案,我看到大多数人被告知要使用beautifulsoup。我不能用那个。我被告知使用列表,然后附加这些列表来查找它。这是到目前为止我的代码。这是糟糕的有很多原因,至少是我不知道我在做什么 import urllib.request page_list=[] local_filename, headers = urllib.request.ur

我正在学习python。由于我是新手,我不允许使用Python的内置库,除非有人告诉我。对于这个问题,我将查找“”的各个href位置。我在这里看到了更多的答案,我看到大多数人被告知要使用beautifulsoup。我不能用那个。我被告知使用列表,然后附加这些列表来查找它。这是到目前为止我的代码。这是糟糕的有很多原因,至少是我不知道我在做什么

import urllib.request
page_list=[]
local_filename, headers = urllib.request.urlretrieve("http://news.ycombinator.com/")
html=open(local_filename)
for line in html:
    page_list.append(line)
for k in range(len(page_list)):
    if '<a href' in page_list[k]:
        href_line=k
href_start = page_list[href_line].find('<a href')
href_end = page_list[href_line].find('</a')
print(page_list[href_start][href_start: href_end])
导入urllib.request
页面列表=[]
local_filename,headers=urllib.request.urlretrieve(“http://news.ycombinator.com/")
html=打开(本地文件名)
对于html中的行:
页面列表。追加(行)
对于范围内的k(len(页面列表)):

如果“你看过他们的API了吗?”,就看看。可悲的是,我真的不太明白,因为很多我还没有听说过。