放风喽 2019-03-07 09:52 采纳率: 0%
浏览 497
已采纳

这个错误怎么解决,不能传整型数字吗

from selenium import webdriver
from bs4 import BeautifulSoup
import sys
import xlwt
workbook = xlwt.Workbook(encoding="utf-8")
browers = webdriver.Chrome()
tt = "青岛"
url = "http://www.tianqi.com/"
browers.get(url)
content1 = browers.find_element_by_css_selector("body > div.hhx_newheader > div > div.tit2.right > ul > li > span.hhx_appLoadSpan > a:nth-child(2)")
content1.click()
browers.switch_to.window(browers.window_handles[1])
content2 = browers.find_element_by_css_selector("body > div.header > div.city_t.pageclear > div > table > tbody > tr > td > h9 > a:nth-child(2)")
content2.click()
content3 = browers.find_element_by_link_text(tt)
content3.click()
browers.switch_to.window(browers.window_handles[2])
liebiao = browers.find_elements_by_partial_link_text("月天气")
def jiexi(element):
element.click()
print("打开了一个月份")
html = browers.page_source
soup = BeautifulSoup(html,"lxml")
title = soup.find(class_="box-t-l").get_text()[:-5]
woeksheet = workbook.add_sheet(title)
x = 0
y = 0
for i in soup.find_all(class_="tqtongji2"):
for ii in i.find_all("li"):
xieru(x,y,woeksheet,ii.get_text(0))

browers.back()

def xieru(xx,yy,worksheet,texttt):
if yy <= 5:
worksheet.write(xx,yy,label=texttt)
yy += 1
else:
yy = 0
xx += 1
worksheet.write(xx,yy,label=texttt)

for i in liebiao:
print(liebiao)
jiexi(i)
path = "{}{}{}".format("D:\测试临时",tt,".xls")
workbook.save(path)

Traceback (most recent call last):
  File "D:/pyxiangmu/shiyanchang2/青岛天气统计.py", line 44, in <module>
    jiexi(i)
  File "D:/pyxiangmu/shiyanchang2/青岛天气统计.py", line 30, in jiexi
    xieru(x,y,woeksheet,ii.get_text(0))
  File "D:\pyxiangmu\venv\lib\site-packages\bs4\element.py", line 955, in get_text
    return separator.join([s for s in self._all_strings(
AttributeError: 'int' object has no attribute 'join'
  • 写回答

2条回答 默认 最新

  • 放风喽 2019-03-07 14:48
    关注

    我把xieru()整个给删除了,把写入数据的操作直接写在jiexi()里了。从根源上解决了问题。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择