Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [split] [Help] Keep getting a 'TypeError' from Django and BeautifulSoup
#1
Hi. I am also new to Django. I want to do the same as you scrape using Django as a web application. the code right now working fine using python3 Jupyter notebook.

import requests
import json
import time
from bs4 import BeautifulSoup as soup

def getLi(text):
    for i in x: 
        if i[0] == "i" and i[1:].isdigit():
            return (i.replace("i",""))
            
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'}

count = 0
link = input("Please enter url to scrape ")
x = link.split("-")
d = soup(requests.get(link).text, 'html.parser')
results = list(map(int, filter(None, [i.text for i in d.find_all('button', {'class':'next-pagination-item'})])))
print (results)
for i in range(min(results), max(results)+1):
    count+=1
    time.sleep(10)  #0.5 * random.random()
    url = ('https://my.lazada.com.my/pdp/review/getReviewList?'
        'itemId='+str(getLi(x))+'&pageSize=5&filter=0&sort=0&pageNo='+str(count))
    print(url)
    req = requests.get(url,headers=headers)
    data = req.json()
    print(count)
    for i in data['model']['items']:
    
        reviewContent = i['reviewContent']
        
        print(reviewContent)
        print('------------------------------------------')
where should I put this code? models.py right? what should I put at views.py and templates folder that contain HTML. Huh Huh
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  TypeError: missing 1 required positional argument (word counter Django app) Drone4four 2 2,231 Jul-11-2019, 09:34 PM
Last Post: Drone4four
  [Help] Keep getting a 'TypeError' from Django and BeautifulSoup Plant_Boy 7 1,418 Jun-13-2018, 04:13 PM
Last Post: Larz60+
  How to create dynamic webscraper in Django using BeautifulSoup Prince_Bhatia 1 3,210 Jan-26-2018, 02:07 PM
Last Post: frostbite

Forum Jump:


Users browsing this thread: 1 Guest(s)