我想抓取这个网页(http://www.zhujiage.com.cn/article/List_2.html)和这个网页(http://www.qinbing.cn/jidanjiage/)的url链接地址。
from urllib2 import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://www.zhujiage.com.cn/article/List_2.html")
bsobj = BeautifulSoup(html,'lxml')
for link in bsobj.find_all(name="a"):
if 'href' in link.attrs:
print link.attrs['href']
上面这段代码只改变网址,前一个网址不能抓取网页URL,后面的网址可以抓取。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
ringa_lee