我正在尝试从html源下载文件。 e、 g
<a class="el" href="classcs1graphics_1_1Circle.html">Circle</a>
<a class="el" href="classcs1graphics_1_1Polygon.html">Polygon</a>
我得到了所有的href,但是我试图得到href的实际内容
下面的代码得到了上面的(很多),并且做得很快。如何获取这些HREF的内容?提前谢谢
埃德
import urllib.request, urllib.error, urllib.parse
from lxml import html
import requests
from bs4 import BeautifulSoup
#get the data from the URL
udata = requests.get('http://www.cs1graphics.org/doc/1.0/hierarchy.html')
#feed it to BeautifulSoup
soup = BeautifulSoup(udata.text,'html.parser')
#get all the <a table records
number_list_items = soup.find_all('a')
#get the rows in the records
for li_row in number_list_items:
print(li_row)
您必须在循环中调用
requests.get()
才能下载内容。它使用相对URL,所以您必须定义基本URL相关问题 更多 >
编程相关推荐