【发布时间】:2015-08-07 14:57:59
【问题描述】:
考虑代码:
from bs4 import BeautifulSoup
from urllib.request import urlopen
content = urlopen('https://example.net/users/101')
soup = BeautifulSoup(content)
divTag = soup.find_all("div", {"class":"classname"})
print(divTag)
for tag in divTag:
ulTags = tag.find_all("ul", {"class":"classname"})
for tag in ulTags:
aTags = tag.find_all("li")
for tag in aTags:
name = tag.find('a')['href']
print(name)
如果我使用,
content = open("try.html","r")
我得到了所需的输出。
这里只有输入用户名和密码才能访问example.net。尽管解析正确完成,但上面的代码没有打印任何内容。如何将会话 cookie 值添加到此代码?
【问题讨论】:
标签: python session cookies web-scraping beautifulsoup