Python Forum
HELP on Unwanted CSV Export Output | Using Selenium to Scrape
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HELP on Unwanted CSV Export Output | Using Selenium to Scrape
#1
Hi guys,

It's been a long time since my last post.

Anyway, I'm having trouble with the CSV export result on a website I am trying to scrape data from.

====================================

Output Problems:
Output in column but just the first column and it only output's the first column of data
[Image: b6Qhek6.png]

Output in rows but just one row
[Image: Imhh7HQ.png]

I just want it to output the typical way
[Image: Vmp6MHp.png]

====================================
Here's a segment of the whole site's html where my particular target is:
# My apology, I do not know how to wrap html in creating a thread and the button "Insert code snippet" doesn't work.
<tbody id="sitesList">
	<tr data-value="11230" class="item-row">
		<td class="text-left"><a href="http://www.example.com" target="_blank">example.com</a> <i class="fa fa-external-link"></i>
			<br><span>» <a href="https://www.domain.com/site/11230.html" target="_blank" class="text-danger">view site details</a></span></td>
		<td>92</td>
		<td>71</td>
		<td>Do Follow</td>
		<td style="font-size:12px;font-family:sans-serif !important;">Education
			<br>Family &amp; Parenting
			<br>Food &amp; Drink
			<br>
		</td>
		<td>Included</td>
		<td><strong>$1</strong></td>
		<td><span data-id="11230" class="btn btn-success btn-sm addtocart">Buy Website $1</span></td>
	</tr>
	<tr data-value="11229" class="item-row">
		<td class="text-left"><a href="http://example1.com/" target="_blank">example1.com</a> <i class="fa fa-external-link"></i>
			<br><span>» <a href="https://www.domain.com/site/11229.html" target="_blank" class="text-danger">view site details</a></span></td>
		<td>65</td>
		<td>34</td>
		<td>Do Follow</td>
		<td style="font-size:12px;font-family:sans-serif !important;">Business &amp; Finance
			<br>General: Multi-Niche
			<br>
		</td>
		<td>Included</td>
		<td><strong>$2</strong></td>
		<td><span data-id="11229" class="btn btn-success btn-sm addtocart">Buy Website $2</span></td>
	</tr>
	<tr data-value="11228" class="item-row">
		<td class="text-left"><a href="https://example2.com" target="_blank">example2.com</a> <i class="fa fa-external-link"></i>
			<div class="tooltip owner_tooltip" style="float: right;opacity: 1;width: 20px;height: 20px;background-size: 100%;"><span class="tooltiptext">Owner Verified</span></div>
			<br><span>» <a href="https://www.domain.com/site/11228.html" target="_blank" class="text-danger">view site details</a></span></td>
		<td>27</td>
		<td>26</td>
		<td>Do Follow</td>
		<td style="font-size:12px;font-family:sans-serif !important;">Cryptocurrency
			<br>
		</td>
		<td>Not Included</td>
		<td><strong>$3</strong></td>
		<td><span data-id="11228" class="btn btn-success btn-sm addtocart">Buy Website $3</span></td>
	</tr>
	<tr data-value="11227" class="item-row">
		<td class="text-left"><a href="https://example3.com" target="_blank">example3.com</a> <i class="fa fa-external-link"></i>
			<br><span>» <a href="https://www.domain.com/site/11227.html" target="_blank" class="text-danger">view site details</a></span></td>
		<td>23</td>
		<td>29</td>
		<td>Do Follow</td>
		<td style="font-size:12px;font-family:sans-serif !important;">Business &amp; Finance
			<br>Health
			<br>SEO &amp; Digital Marketing
			<br>
		</td>
		<td>Included</td>
		<td><strong>$4</strong></td>
		<td><span data-id="11227" class="btn btn-success btn-sm addtocart">Buy Website $4</span></td>
	</tr>
</tbody>
====================================

I'm using selenium and here's my code:
siteList_tds = driver.find_elements(By.XPATH, "//tbody[@id='sitesList']//tr//td")
with open('test.csv', 'w') as f:
    write = csv.writer(f)
    for s in siteList_tds:
        write.writerow(s.text) ## or write.writerow([s.text])
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Unwanted execution of unittest ThomasFab 9 1,947 Nov-15-2022, 05:33 PM
Last Post: snippsat
Question Export Python output to Excel skyline1397 1 1,984 Jun-26-2022, 05:10 AM
Last Post: skyline1397
  Removing the unwanted data from a file jehoshua 14 3,974 Feb-01-2022, 09:56 PM
Last Post: jehoshua
  How to scrape and count star rating using Selenium and Python? celinafregoso99 1 3,265 Feb-15-2021, 02:45 PM
Last Post: kashcode
  How to eliminate unwanted spaces Mohan 5 2,803 Jun-04-2020, 08:34 AM
Last Post: buran
  export sql output to excel Kranthi 6 7,680 Oct-17-2018, 02:01 AM
Last Post: Kranthi
  Unwanted delay between looped synth plays WolfeCreek 1 2,284 Aug-02-2018, 09:24 PM
Last Post: Vysero
  Unwanted variable change in module dannyH 2 2,634 May-08-2018, 05:33 PM
Last Post: dannyH
  How to export map output from Python medurisu2002 1 4,284 Dec-18-2016, 12:56 AM
Last Post: Larz60+
  Unwanted random generation of scripted Shapes in GASP diemildefreude 3 5,100 Oct-23-2016, 03:11 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020