我是新来的。我想得到所有隐藏的链接
<div class="page-body">
<div class="page-title"></div>
<div class="page cursorPointer">
<a title="" data-placement="top" data-toggle="tooltip" href="#" data-original-title="Verified"></a></div>
</div>
这是我的剧本:
#!/usr/bin/python3
from selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd
from selenium.webdriver.chrome.options import Options
import requests
import re
from openpyxl import Workbook
driver = webdriver.Chrome(options=options)
driver.get(
"https://someurl.com")
pagelist = []
content = driver.page_source
soup = BeautifulSoup(content, 'lxml')
for a in soup.findAll('div', attrs={'class': 'page cursorPointer'}):
page = a.find_element_by_xpath("//a[@href]")
pagelist.append(page.get_attribute("href"))
df = pd.DataFrame({'Page': pagelist})
df.to_excel('pagelist.xlsx', index=False, encoding='utf-8')
我有个错误:
page = a.find_element_by_xpath("//a[@href]") TypeError: 'NoneType' object is not callable
发生这种情况是因为您正在对soup对象使用selenium方法。 试着这样做:
相关问题 更多 >
编程相关推荐