来自beautifulsoup的我的爬虫不再编写网页的内容了

时间:2018-02-13 16:30:13

标签: python beautifulsoup web-crawler

我编写了一个网络抓取代码,用于从Waze实时地图中收集数据。它曾经工作并成功地在文本文件中记下了响应的内容。但是,现在它将保存在文本文件中的唯一输出是“'b'”值。它似乎无法访问网页的内容。之前我添加了标题,因为我使用的链接是页面的RSS源。这是我的代码:

# Extract the object from Waze live map
from bs4 import BeautifulSoup
import urllib.request
import requests


class AppURLOpener(urllib.request.FancyURLopener):
  version = "Mozilla/5.0"

def event (left, right, bottom, up):

link = "https://www.waze.com/rtserver/web/TGeoRSS?ma=600&mj=100&mu=100&left="+ left + "&right=" + right + "&bottom=" + bottom + "&top=" + \
       up + "&_=1504116242156"
print (link)
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)     Chrome/37.0.2049.0 Safari/537.36'}
r = requests.get(link)
rs = r.content
print (rs)
soup = BeautifulSoup(rs, 'html.parser')
soup2 = soup.encode('UTF-8')
content = str(soup2)
with open("I-5 LA.txt", "a") as myfile:
    myfile.write(content)

我没有收到任何错误,问题是JSON响应的内容不再写入文本文件了。任何人都可以帮我这个吗?

0 个答案:

没有答案
相关问题