我有一个生成此内容的网站。
这是页面后面的HTML。
我试图弄清楚如何刮出3、15和28。同一行中也有3个空白节点。我想捕获所有内容,因为有时会填写这些数字。然后,在下一行中有25,在下一行中有16。这是我必须开始的通用代码。
page_source = []
for i in range(1, 11):
url = 'https://airflow.com/admin/?page={}'.format(i)
page_source.append(url)
# count items in urllist
num = len(page_source)
# And grab the page HTML source
# The webdriver will wait for a page to load by default via .get() method.
for line in page_source:
print(line)
wd.get(line)
html_page = wd.page_source
soup = bs(html_page, 'lxml')
for link in soup.find_all('a'):
#print(link.get('href'))
string = link.get('href')
id = re.match('(.*)_id=(\w+)', string).group(2)
print(id)
答案 0 :(得分:1)
您可以使用bs4
查找并配对所有text
和circle
标签:
from bs4 import BeautifulSoup as soup
d = soup(content, 'html.parser')
result = [{'text':a.text, 'color':b['stroke']} for a, b in zip(d.find_all('text'), d.find_all('circle')) if a.text]