我已经用BeautifulSoup做了一些基本的web抓取。在我的下一个项目中,我选择了刮取指定用户的facebook好友列表。问题是,只有当你登录时,facebook才能让你看到好友列表。因此,我的问题是,我是否可以绕过它,如果没有,我是否可以让BeautifulSoup像登录一样?
这是我的密码:
from urllib.request import urlopen
from bs4 import BeautifulSoup
url = input("enter url: ")
try:
page = urlopen(url)
except:
print("Error opening the URL")
soup = BeautifulSoup(page, 'html.parser')
content = soup.find('div', {"class": "_3i9"})
friends = ''
for i in content.findAll('a'):
friends = friends + ' ' + i.text
print(friends)
发布于 2020-03-14 22:27:52
BeautifulSoup不要求您使用URL。相反:
with open("path/to/ParentTag.html", encoding="utf8") as html:
soup = BeautifulSoup(html, "html.parser")
发布于 2019-08-24 05:26:33
问题是,只有当你登录时,facebook才能让你看到好友列表
您可以使用Selenium克服这一问题。您需要它来验证自己,然后才能找到用户。一旦您找到了它,您可以通过两种方式进行:
driver.page_source
获得HTML源代码,然后使用Beatifulhttps://stackoverflow.com/questions/57638076
复制