我正在尝试从父网页获取指向另一篇文章的指针链接。下面的代码显示了该网站的外观。所有指针网页均以 开头http://lenta.ru/。所以我的代码尝试从源 html 代码中找到该 href 元素。但是,它不会打印文章底部的指针链接。import requestsfrom lxml import htmlfrom bs4 import BeautifulSoupfrom urllib.request import urlopentmp = "https://uynaa.wordpress.com/2011/05/04/%d0%be%d1%81%d0%b0%d0%bc%d0%b0-%d0%b1%d0%b8%d0%bd-%d0%bb%d0%b0%d0%b4%d0%b5%d0%bd%d0%b8%d0%b9%d0%b3-%d1%8f%d0%b0%d0%b6-%d0%b8%d0%bb%d1%80%d2%af%d2%af%d0%bb%d1%81%d1%8d%d0%bd-%d0%b1%d1%8d/"html = urlopen(tmp).read()soup = BeautifulSoup(html, "lxml")for a in soup.find_all('a', href=True): if "lenta.ru" in a: print(a)我怎么做?
添加回答
举报
0/150
提交
取消