python-2.7 - 使用 BeautifulSoup 抓取时,我得到一个 0kb 的 TXT 文件
问题描述
我正在尝试从此代码中抓取这些信息,但输出为空:
<td class="views-field views-field-subscription-client-name">
<div>
<strong>ANNA Elliassaint René et Marjorie</strong>
<div class="show-details row-details-3390489 collapse in" aria-expanded="true" style="">
<p>Tél : 0671328654</p>
<p>kartelizi9@gmail.com</p>
</div>
这是我抓取这些信息的代码:
import urllib2
from bs4 import BeautifulSoup
for x in range(1,4):
numb = str(x)
url = "https://fr.eni.com/appel-entrant-particuliers/?page="+numb
page = urllib2.urlopen(url).read()
soup = BeautifulSoup(page, 'html.parser')
html =soup.contents
html = soup.prettify("utf-8")
records = []
#try:
for scrape_email in soup.find_all('td', attrs={'class': 'views-field views-field-subscription-client-name'}):
scrape = scrape_email.text
records.append(scrape)
for scrape in records:
f = open("myfile.txt", "a+")
f.write(scrape)
f.write("\n")
f.close()
print("OK" +(numb))
我想刮掉所有 4 页上的所有信息,请提供任何解决方案
解决方案
推荐阅读
- python - 如何重写 sympy 中的表达式以遵循用于方程式的特定形式?
- python - 使用 MFA 登录 chrome 时的陈旧元素 - Selenium Python
- reactjs - React Native 上的 WebSocket (onmessage)
- python - 为什么我的 python 代码的运行时间这么长,我该怎么做才能让它运行得更快?
- c# - 在 Azure 函数中将 Activity 作为参数传递时,TelemetryClient.StartOperation 总是失败
- logging - 气流/作曲家-信息日志被发送到标准错误?- 导致日志记录显示为错误
- php - 如何在 PHP 脚本执行旁边使用 Caddy 提供静态文件?(交响乐)
- java - 如何将完整的数据库架构公开为 OData 服务
- javascript - 跨 2 个 js 文件保存和读取变量的问题
- scala - 如何使用 Slick 生成条件插入